def lock_or_exit(self, lock_filename, message="process %s is already running"):
pid = psutil.Process().pid
if os.path.exists(lock_filename):
with open(lock_filename) as lockfile:
old_pid = int(lockfile.read())
if old_pid in psutil.pids():
logging.info(message % old_pid)
sys.exit(1)
else:
os.unlink(lock_filename)
评论列表
文章目录