def trylock(self):
if self.lockfile is None or self.lockfile.closed:
self.lockfile = open(self.path, 'a')
try:
if os.name == 'nt':
msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_NBLCK, 1)
else:
fcntl.lockf(self.lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
return True
except IOError,e:
if e.errno in (errno.EACCES, errno.EAGAIN):
return False
raise
评论列表
文章目录