8000 Use lockfile to prevent race conditions · matplotlib/matplotlib@ca750bf · GitHub
[go: up one dir, main page]

Skip to content

Commit ca750bf

Browse files
committed
Use lockfile to prevent race conditions
Creation of the font cache has race conditions
1 parent c9351bd commit ca750bf

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lib/matplotlib/font_manager.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,10 +1405,9 @@ def findfont(prop, fontext='ttf'):
14051405
else:
14061406
_fmcache = None
14071407

1408-
if not 'TRAVIS' in os.environ:
1409-
cachedir = get_cachedir()
1410-
if cachedir is not None:
1411-
_fmcache = os.path.join(cachedir, 'fontList.json')
1408+
cachedir = get_cachedir()
1409+
if cachedir is not None:
1410+
_fmcache = os.path.join(cachedir, 'fontList.json')
14121411

14131412
fontManager = None
14141413

@@ -1419,8 +1418,14 @@ def findfont(prop, fontext='ttf'):
14191418

14201419
def _rebuild():
14211420
global fontManager
1421+
import lockfile
1422+
14221423
fontManager = FontManager()
1424+
14231425
if _fmcache:
1426+
with lockfile.Lockfile(_fmcache):
1427+
json_dump(fontManager, _fmcache)
1428+
14241429
json_dump(fontManager, _fmcache)
14251430
verbose.report("generated new fontManager")
14261431

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
setupext.Numpy(),
6969
setupext.Dateutil(),
7070
setupext.Pytz(),
71+
setupext.Lockfile(),
7172
setupext.Cycler(),
7273
setupext.Tornado(),
7374
setupext.Pyparsing(),

setupext.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,24 @@ def get_install_requires(self):
11711171
return ['pytz']
11721172

11731173

1174+
class LockFile(SetupPackage):
1175+
name = 'lockfile'
1176+
1177+
def check(self):
1178+
try:
1179+
import lockfile
1180+
except ImportError:
1181+
return (
1182+
'lockfile was not found. '
1183+
'pip will attempt to install it '
1184+
'after matplotlib.')
1185+
1186+
return 'using lockfile version %s' % lockfile.__version__
1187+
1188+
def get_install_requires(self):
1189+
return ['lockfile']
1190+
1191+
11741192
class Cycler(SetupPackage):
11751193
name = "cycler"
11761194

0 commit comments

Comments
 (0)
0