SHARE
TWEET

Untitled

a guest Oct 21st, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def check_pid(pid):
  2.     try:
  3.         os.kill(pid, 0)
  4.     except OSError:
  5.         return False
  6.     else:
  7.         return True
  8.  
  9. pid = None
  10. try:
  11.     pid = int(open("script_name.pid").read())
  12. except:
  13.     pass
  14.  
  15. if pid:
  16.     if check_pid(pid):
  17.         logging.info("An instance of script_name is already running: PID={}. Bye".format(pid))
  18.         sys.exit(0)
  19.  
  20. pid = os.getpid()
  21. open("script_name.pid","w").write(str(pid))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top