pidfile = "/tmp/server.pid"
def check_pid(pid):
""" Check For the existence of a unix pid. """
try:
os.kill(pid, 0)
except OSError:
return False
else:
return True
if os.path.isfile(pidfile):
pid = long(open(pidfile, 'r').read())
if check_pid(pid):
print "%s already exists, exiting" % pidfile
sys.exit()
pid = str(os.getpid())
file(pidfile, 'w').write(pid)
# actual code
# finish
os.unlink(pidfile)
* This source code was highlighted with Source Code Highlighter.