def getLock(self,lock_path,force=False,timeout=30,filename="easyops.lock"):
import fcntl
lockFile = os.path.join(lock_path,filename)
#fp = open(lockFile,'w')
try:
if os.path.isfile(lockFile):
os.chmod(lockFile, 0o777)
except:
pass
self.fp[lockFile] = open(lockFile,'w')
count = 0
while True:
if count > timeout:
return False
count += 1
try:
fcntl.flock(self.fp[lockFile],fcntl.LOCK_EX|fcntl.LOCK_NB)
except IOError:
if force == True:
return True
gevent.sleep(1)
else:
return True
评论列表
文章目录