Skip to content

Commit 72444e6

Browse files
committed
Move font cache rebuild out of exception handler
The purpose of the patch is to make tracebacks from cache rebuilding clearer.
1 parent d99714f commit 72444e6

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/matplotlib/font_manager.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,17 +1356,20 @@ def _rebuild():
13561356
if _fmcache:
13571357
try:
13581358
fontManager = json_load(_fmcache)
1359-
if (not hasattr(fontManager, '_version') or
1360-
fontManager._version != FontManager.__version__):
1361-
_rebuild()
1362-
else:
1363-
fontManager.default_size = None
1364-
_log.debug("Using fontManager instance from %s", _fmcache)
1365-
except TimeoutError:
1366-
raise
1367-
except Exception:
1368-
_rebuild()
1369-
else:
1359+
except FileNotFoundError:
1360+
_log.debug("No font cache found %s", _fmcache)
1361+
except json.JSONDecodeError:
1362+
_log.warning("Font cache parsing failed %s", _fmcache)
1363+
1364+
if (not hasattr(fontManager, '_version') or
1365+
fontManager._version != FontManager.__version__):
1366+
_log.debug("Font cache needs rebuild (version mismatch)")
1367+
fontManager = None
1368+
else:
1369+
fontManager.default_size = None
1370+
_log.debug("Using fontManager instance from %s", _fmcache)
1371+
1372+
if fontManager is None:
13701373
_rebuild()
13711374

13721375
def findfont(prop, **kw):

0 commit comments

Comments
 (0)