From 13af9808edd3fb655ddf7598f2b2fdd186f20c37 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Sun, 17 Jul 2016 11:19:53 -0400 Subject: [PATCH 1/2] Raise lock timeout as actual exception --- lib/matplotlib/cbook.py | 13 ++++++++----- lib/matplotlib/font_manager.py | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index a8b636e17ed0..e9197c1470f0 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -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. +removing these folders and trying again. """ @@ -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()) @@ -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: diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 5e5a95232b2b..1d0ba8377148 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -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: From 2e0613a4cd6990f24edaaa5bb854341bfe2f8118 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 19 Jul 2016 14:59:32 -0400 Subject: [PATCH 2/2] Fix typo --- lib/matplotlib/cbook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index e9197c1470f0..0216ccb9c501 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -2580,7 +2580,7 @@ def _putmask(a, mask, values): 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 +lock. If you are sure no other matplotlib process is running try removing these folders and trying again. """