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

Skip to content

Commit 045acbc

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 eb18cb2 commit 045acbc

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ property. This now raises a TypeError.
6262
`.FileMovieWriter` now defaults to writing temporary frames in a temporary
6363
directory, which is always cleared at exit. In order to keep the individual
6464
frames saved on the filesystem, pass an explicit *frame_prefix*.
65+
66+
`.font_manager.json_dump` now locks the font manager dump file
67+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68+
... to prevent multiple processes from writing to it at the same time.

lib/matplotlib/font_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def json_dump(data, filename):
918918
--------
919919
json_load
920920
"""
921-
with open(filename, 'w') as fh:
921+
with cbook._lock_path(filename), open(filename, 'w') as fh:
922922
try:
923923
json.dump(data, fh, cls=_JSONEncoder, indent=2)
924924
except OSError as e:
@@ -1335,8 +1335,7 @@ def get_font(filename, hinting_factor=None):
13351335
def _rebuild():
13361336
global fontManager
13371337
fontManager = FontManager()
1338-
with cbook._lock_path(_fmcache):
1339-
json_dump(fontManager, _fmcache)
1338+
json_dump(fontManager, _fmcache)
13401339
_log.info("generated new fontManager")
13411340

13421341

0 commit comments

Comments
 (0)
0