def release(self):
"""
Release the lock.
"""
# If we went over the lock duration (timeout), we need to exit to avoid
# accidentally releasing a lock that was acquired by another process.
if not self.held:
logger.warning('Tried to release unheld lock: %r', self)
return False
try:
# XXX: There is a possible race condition here -- this could be
# actually past the timeout due to clock skew or the delete
# operation could reach the server after the timeout for a variety
# of reasons. The only real fix for this would be to use a check
# and delete operation, but that is backend dependent and not
# supported by the cache API.
self.cache.delete(self.lock_key)
except Exception as e:
logger.exception(e)
finally:
self.__acquired_at = None
return True
评论列表
文章目录