def acquire(self, blocking=False):
import fcntl # @UnresolvedImport
flags = os.O_CREAT | os.O_WRONLY
self.fd = os.open(self.filename, flags)
mode = fcntl.LOCK_EX
if not blocking:
mode |= fcntl.LOCK_NB
try:
fcntl.flock(self.fd, mode)
self.locked = True
return True
except IOError:
e = sys.exc_info()[1]
if e.errno not in (errno.EAGAIN, errno.EACCES):
raise
os.close(self.fd)
self.fd = None
return False
评论列表
文章目录