Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check_pid(pid):
- try:
- os.kill(pid, 0)
- except OSError:
- return False
- else:
- return True
- pid = None
- try:
- pid = int(open("script_name.pid").read())
- except:
- pass
- if pid:
- if check_pid(pid):
- logging.info("An instance of script_name is already running: PID={}. Bye".format(pid))
- sys.exit(0)
- pid = os.getpid()
- open("script_name.pid","w").write(str(pid))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement