Skip to content

Instantly share code, notes, and snippets.

@mickhan
Created May 30, 2013 09:26
Show Gist options
  • Save mickhan/5676751 to your computer and use it in GitHub Desktop.
Save mickhan/5676751 to your computer and use it in GitHub Desktop.
python pidfile
import os
import sys
pid = str(os.getpid())
pidfile = "/tmp/pidfilename.pid"
if os.path.isfile(pidfile):
print "%s already exists, exiting" % pidfile
sys.exit()
else:
file(pidfile, 'w').write(pid)
# Do something
os.unlink(pidfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment