def isSingleInstance(flavor_id=""):
global fp
basename = os.path.splitext(os.path.abspath(sys.argv[0]))[0].replace(
"/", "-").replace(":", "").replace("\\", "-") + '-%s' % flavor_id + '.lock'
lockfile = os.path.normpath(tempfile.gettempdir() + '/' + basename)
if sys.platform == 'win32':
try:
if os.path.exists(lockfile):
os.unlink(lockfile)
fp = os.open(
lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR)
except OSError:
return False
else: # non Windows
fp = open(lockfile, 'w')
try:
fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
return False
return True
评论列表
文章目录