def acquire(self):
try:
self._lock = open(self.lock_file, "w")
flock(self._lock, LOCK_EX | LOCK_NB)
logging.debug("Acquired exclusive lock on file: %s" % self.lock_file)
return self._lock
except Exception:
logging.debug("Error acquiring lock on file: %s" % self.lock_file)
if self._lock:
self._lock.close()
raise OperationError("Could not acquire lock on file: %s!" % self.lock_file)
评论列表
文章目录