8000 Move locking of fontlist.json *into* json_dump. by anntzer · Pull Request #16111 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api/next_api_changes/behaviour.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,6 @@ The parameter ``s`` to `.Axes.annotate` and `.pyplot.annotate` is renamed to
The old parameter name remains supported, but
support for it will be dropped in a future Matplotlib release.

`.font_manager.json_dump` now locks the font manager dump file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... to prevent multiple processes from writing to it at the same time.
8 changes: 5 additions & 3 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,11 @@ def json_dump(data, filename):
File paths that are children of the Matplotlib data path (typically, fonts
shipped with Matplotlib) are stored relative to that data path (to remain
valid across virtualenvs).

This function temporarily locks the output file to prevent multiple
processes from overwriting one another's output.
"""
with open(filename, 'w') as fh:
with cbook._lock_path(filename), open(filename, 'w') as fh:
try:
json.dump(data, fh, cls=_JSONEncoder, indent=2)
except OSError as e:
Expand Down Expand Up @@ -1333,8 +1336,7 @@ def _rebuild():
global fontManager
_log.info("Generating new fontManager, this may take some time...")
fontManager = FontManager()
with cbook._lock_path(_fmcache):
json_dump(fontManager, _fmcache)
json_dump(fontManager, _fmcache)


try:
Expand Down
0