diff options
author | Paul Sherwood <paul.sherwood@codethink.co.uk> | 2016-03-05 16:46:27 +0000 |
---|---|---|
committer | Paul Sherwood <paul.sherwood@codethink.co.uk> | 2016-03-05 16:46:27 +0000 |
commit | 30c16ea0b991ad93d723aeaefcc45f896388ac10 (patch) | |
tree | d22f5cd267516483c87b09c8de7f4e1b8f611da1 | |
parent | 57bb4864b12eacb6ff78e0464d6e88c44caf4ed1 (diff) | |
download | ybd-claim-can-ctrl-c.tar.gz |
Another attempt at claim, can ctrl-cclaim-can-ctrl-c
-rw-r--r-- | ybd/assembly.py | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/ybd/assembly.py b/ybd/assembly.py index 0910ecf..6118401 100644 --- a/ybd/assembly.py +++ b/ybd/assembly.py @@ -167,30 +167,23 @@ def lockfile(defs, this): @contextlib.contextmanager def claim(defs, this): - l = open(lockfile(defs, this), 'a') - try: - fcntl.flock(l, fcntl.LOCK_EX | fcntl.LOCK_NB) - except IOError as e: - l.close() - if e.errno in (errno.EACCES, errno.EAGAIN): - # flock() will report EACCESS or EAGAIN when the lock fails. - if app.config.get('instances', 1) == 1: + with open(lockfile(defs, this), 'a') as l: + try: + fcntl.flock(l, fcntl.LOCK_EX | fcntl.LOCK_NB) + except Exception as e: + if e.errno in (errno.EACCES, errno.EAGAIN): + # flock() will report EACCESS or EAGAIN when the lock fails. + raise RetryException(defs, this) + else: import traceback traceback.print_exc() app.exit(this, 'ERROR: a surprise exception happened', '') - raise RetryException(defs, this) - else: - raise - except: - l.close() - raise - - try: - yield - finally: - l.close() - if os.path.isfile(lockfile(defs, this)): - os.remove(lockfile(defs, this)) + try: + yield + finally: + if os.path.isfile(lockfile(defs, this)): + os.remove(lockfile(defs, this)) + def install_contents(defs, component): |