Skip to content

Commit

Permalink
Merge pull request #2221 from marqh/lock
Browse files Browse the repository at this point in the history
limit filelock use
  • Loading branch information
lbdreyer authored Oct 28, 2016
2 parents bb9d169 + 39dd0bf commit e3bc58d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/iris/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`."""
Expand Down

0 comments on commit e3bc58d

Please sign in to comment.