def __acquire(self):
max_lock = max_lock_seconds()
def timed_out():
logging.error("Lock timed out after {} seconds".format(max_lock))
# NOTE(CD):
#
# Bail and rely on the operating system to close the open lock
# file descriptor. They are closed on our behalf according to
# the POSIX standard. See https://linux.die.net/man/2/exit
#
# We emulate Ctrl-C instead of raising SystemExit via sys.exit()
# since exceptions are per-thread. SystemExit causes the
# interpreter to exit if unhandled. This is the only
# reliable way to trigger an exception in the main thread
# to make this testable. Open to improvements.
#
# The interpreter exits with status 1.
#
# See https://goo.gl/RXsXEs
_thread.interrupt_main()
self.timer = threading.Timer(max_lock, timed_out)
self.timer.start()
# acquire file lock
fcntl.flock(self.fd, fcntl.LOCK_EX)
评论列表
文章目录