From 39dd0bf24b1c35a64ee103e84cf50294354f0a77 Mon Sep 17 00:00:00 2001 From: marqh Date: Fri, 28 Oct 2016 08:48:07 +0000 Subject: [PATCH] only lock file when in create_missing --- lib/iris/tests/__init__.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/iris/tests/__init__.py b/lib/iris/tests/__init__.py index d8834baa78..47baf2e409 100644 --- a/lib/iris/tests/__init__.py +++ b/lib/iris/tests/__init__.py @@ -734,9 +734,14 @@ def _create_missing(): figure.savefig(hash_fname) msg = 'Creating imagerepo entry: {} -> {}' print(msg.format(unique_id, uri)) - with open(repo_fname, 'wb') as fo: - json.dump(repo, codecs.getwriter('utf-8')(fo), indent=4, - sort_keys=True) + lock = filelock.FileLock(repo_fname) + # The imagerepo.json file is a critical resource, so ensure + # thread safe read/write behaviour via platform independent + # file locking. + with lock.acquire(timeout=600): + with open(repo_fname, 'wb') as fo: + json.dump(repo, codecs.getwriter('utf-8')(fo), + indent=4, sort_keys=True) # TBD: Push this fix to imagehash (done!) # See https://github.com/JohannesBuchner/imagehash/pull/31 @@ -804,11 +809,7 @@ def check_graphic(self): """ fname = os.path.join(_RESULT_PATH, 'imagerepo.lock') - lock = filelock.FileLock(fname) - # The imagerepo.json file is a critical resource, so ensure thread - # safe read/write behaviour via platform independent file locking. - with lock.acquire(timeout=600): - self._assert_graphic() + self._assert_graphic() def _remove_testcase_patches(self): """Helper to remove per-testcase patches installed by :meth:`patch`."""