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

Skip to content

Commit ae891ae

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 76c764c commit ae891ae

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,8 @@ deprecation warning.
100100

101101
Previously setting the *ecolor* would turn off automatic color cycling for the plot, leading to the
102102
the lines and markers defaulting to whatever the first color in the color cycle was in the case of
103-
multiple plot calls.
103+
multiple plot calls.
104+
105+
`.font_manager.json_dump` now locks the font manager dump file
106+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107+
... 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
@@ -914,11 +914,14 @@ def json_dump(data, filename):
914914
shipped with Matplotlib) are stored relative to that data path (to remain
915915
valid across virtualenvs).
916916
917+
This function temporarily locks the output file to prevent multiple
918+
processes from overwriting one another's output.
919+
917920
See Also
918921
--------
919922
json_load
920923
"""
921-
with open(filename, 'w') as fh:
924+
with cbook._lock_path(filename), open(filename, 'w') as fh:
922925
try:
923926
json.dump(data, fh, cls=_JSONEncoder, indent=2)
924927
except OSError as e:
@@ -1338,8 +1341,7 @@ def _rebuild():
13381341
global fontManager
13391342
_log.info("Generating new fontManager, this may take some time...")
13401343
fontManager = FontManager()
1341-
with cbook._lock_path(_fmcache):
1342-
json_dump(fontManager, _fmcache)
1344+
json_dump(fontManager, _fmcache)
13431345

13441346

13451347
try:

0 commit comments

Comments
 (0)
0