8000 Move locking of fontlist.json *into* json_dump. · matplotlib/matplotlib@bf869e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit bf869e7

Browse files
committed
Move locking of fontlist.json *into* json_dump.
This makes it easier for end users to call json_dump (which is public API) safely, given that _lock_path is not public API.
1 parent 5914990 commit bf869e7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@ shape ``(n, 2)`` would plot the first column of *x* against the first column
7070
of *y*, the second column of *x* against the second column of *y*, **and** the
7171
first column of *x* against the third column of *y*. This now raises an error
7272
instead.
73+
74+
`.font_manager.json_dump` now locks the font manager dump file
75+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76+
... to prevent multiple processes from writing to it at the same time.

lib/matplotlib/font_manager.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,11 +911,14 @@ def json_dump(data, filename):
911911
shipped with Matplotlib) are stored relative to that data path (to remain
912912
valid across virtualenvs).
913913
914+
This function temporarily locks the output file to prevent multiple
915+
processes from overwriting one another's output.
916+
914917
See Also
915918
--------
916919
json_load
917920
"""
918-
with open(filename, 'w') as fh:
921+
with cbook._lock_path(filename), open(filename, 'w') as fh:
919922
try:
920923
json.dump(data, fh, cls=_JSONEncoder, indent=2)
921924
except OSError as e:
@@ -1335,8 +1338,7 @@ def get_font(filename, hinting_factor=None):
13351338
def _rebuild():
13361339
global fontManager
13371340
fontManager = FontManager()
1338-
with cbook._lock_path(_fmcache):
1339-
json_dump(fontManager, _fmcache)
1341+
json_dump(fontManager, _fmcache)
13401342
_log.info("generated new fontManager")
13411343

13421344

0 commit comments

Comments
 (0)
0