def unlock(self):
"""Unlocks the LockFile."""
if self._fileobj:
# To avoid race conditions with the next caller
# waiting for the lock file, it is simply
# truncated instead of removed.
try:
fcntl.lockf(self._fileobj, fcntl.LOCK_UN)
self._fileobj.truncate(0)
self._fileobj.close()
self._lock.release()
except EnvironmentError:
# If fcntl, or the file operations returned
# an exception, drop the lock. Do not catch
# the exception that could escape from
# releasing the lock.
self._lock.release()
raise
finally:
self._fileobj = None
else:
if self._provide_mutex:
assert not self._lock.locked
评论列表
文章目录