Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise lock timeout as actual exception #6777

Merged
merged 2 commits into from
Jul 25, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2577,10 +2577,11 @@ def _putmask(a, mask, values):
return np.copyto(a, values, where=mask)

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


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

class TimeoutError(RuntimeError):
pass

def __init__(self, path):
self.path = path
self.end = "-" + str(os.getpid())
Expand All @@ -2607,18 +2611,17 @@ def __init__(self, path):

def __enter__(self):
retries = 50
sleeptime = 1
sleeptime = 0.1
while retries:
files = glob.glob(self.pattern)
if files and not files[0].endswith(self.end):
time.sleep(sleeptime)
sleeptime *= 1.1
retries -= 1
else:
break
else:
err_str = _lockstr.format(self.pattern)
raise RuntimeError(err_str)
raise self.TimeoutError(err_str)

if not files:
try:
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,8 @@ def _rebuild():
else:
fontManager.default_size = None
verbose.report("Using fontManager instance from %s" % _fmcache)
except cbook.Locked.TimeoutError:
raise
except:
_rebuild()
else:
Expand Down