handle release with exception
@@ -108,6 +108,8 @@ def lock_directory(cache_dir, timeout=10, poll_interval=0.05):
os.close(fd)
t_start = time.time()
+ fd = None
+ try:
while True:
fd = acquire(lock_file)
if fd is not None:
@@ -118,6 +120,8 @@ def lock_directory(cache_dir, timeout=10, poll_interval=0.05):
'cannot be acquired')
else:
time.sleep(poll_interval)
+ finally: # exceptions can be raised from yield
+ if fd is not None:
release(fd)
