Better wrapper function exception handling
This commit is contained in:
@@ -17,15 +17,18 @@ def simple_locking(lock_id, expiration=None):
|
|||||||
# Trying to acquire lock
|
# Trying to acquire lock
|
||||||
lock = Lock.acquire_lock(lock_id, expiration)
|
lock = Lock.acquire_lock(lock_id, expiration)
|
||||||
except LockError:
|
except LockError:
|
||||||
# Unable to acquire lock
|
# Unable to acquire lock - non fatal
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# Lock acquired, proceed normally, release lock afterwards
|
# Lock acquired, proceed normally, release lock afterwards
|
||||||
logger.debug('acquired lock: %s' % lock_id)
|
logger.debug('acquired lock: %s' % lock_id)
|
||||||
result = function(*args, **kwargs)
|
try:
|
||||||
lock.release()
|
return function(*args, **kwargs)
|
||||||
return result
|
except:
|
||||||
finally:
|
# Re raise any exception that occured when calling wrapped
|
||||||
lock.release()
|
# function
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
lock.release()
|
||||||
return wraps(function)(wrapper)
|
return wraps(function)(wrapper)
|
||||||
return inner_decorator
|
return inner_decorator
|
||||||
|
|||||||
Reference in New Issue
Block a user