Skip to content

Commit 38a32d9

Browse files
authored
Merge pull request #6777 from mdboom/fix-font-cache-rebuild-timeout
Raise lock timeout as actual exception
2 parents ba8bee1 + 2e0613a commit 38a32d9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/matplotlib/cbook.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -2577,10 +2577,11 @@ def _putmask(a, mask, values):
25772577
return np.copyto(a, values, where=mask)
25782578

25792579
_lockstr = """\
2580-
LOCKERROR: matplotlib is trying to acquire the lock {!r}
2580+
LOCKERROR: matplotlib is trying to acquire the lock
2581+
{!r}
25812582
and has failed. This maybe due to any other process holding this
2582-
lock. If you are sure no other matplotlib process in running try
2583-
removing this folder(s) and trying again.
2583+
lock. If you are sure no other matplotlib process is running try
2584+
removing these folders and trying again.
25842585
"""
25852586

25862587

@@ -2598,6 +2599,9 @@ class Locked(object):
25982599
"""
25992600
LOCKFN = '.matplotlib_lock'
26002601

2602+
class TimeoutError(RuntimeError):
2603+
pass
2604+
26012605
def __init__(self, path):
26022606
self.path = path
26032607
self.end = "-" + str(os.getpid())
@@ -2607,18 +2611,17 @@ def __init__(self, path):
26072611

26082612
def __enter__(self):
26092613
retries = 50
2610-
sleeptime = 1
2614+
sleeptime = 0.1
26112615
while retries:
26122616
files = glob.glob(self.pattern)
26132617
if files and not files[0].endswith(self.end):
26142618
time.sleep(sleeptime)
2615-
sleeptime *= 1.1
26162619
retries -= 1
26172620
else:
26182621
break
26192622
else:
26202623
err_str = _lockstr.format(self.pattern)
2621-
raise RuntimeError(err_str)
2624+
raise self.TimeoutError(err_str)
26222625

26232626
if not files:
26242627
try:

lib/matplotlib/font_manager.py

+2
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,8 @@ def _rebuild():
14461446
else:
14471447
fontManager.default_size = None
14481448
verbose.report("Using fontManager instance from %s" % _fmcache)
1449+
except cbook.Locked.TimeoutError:
1450+
raise
14491451
except:
14501452
_rebuild()
14511453
else:

0 commit comments

Comments
 (0)