def check_pidfile(pidfile, debug):
<EOL>if os.path.isfile(pidfile):<EOL><INDENT>pidfile_handle = open(pidfile, '<STR_LIT:r>')<EOL>try:<EOL><INDENT>pid = int(pidfile_handle.read())<EOL>pidfile_handle.close()<EOL>if check_pid(pid, debug):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>os.unlink(pidfile)<EOL><DEDENT>pid = str(os.getpid())<EOL>open(pidfile, '<STR_LIT:w>').write(pid)<EOL>return False<EOL>
Check that a process is not running more than once, using PIDFILE