On 07/21/2009 07:10 PM, Christopher Armstrong wrote:
It's not necessarily a twistd process. It could be any process with
the same pid. checkPID only checks to see if the pid exists, not that
it's the PID of a twistd process.
Disclaimer is, I might be extremely naive here. I have to admit I wasn't
able to figure out when checkPID is called (before or after a possible
daemonization? Since with how you have to write daemons in UNIX, doing a
os.getpid() _before_ daemonizing is not going to work the way I intend
it to).
Anyway, what is currently done is: os.kill is invoked with signal 0, if
we get no OSError then sys.exit is invoked.
What I propose is if no OSError is raised, we first check that
os.getpid() is different from the pid we read from the file, and if they
are equal we remove the stale file.
Patch against r27172 attached.
Don't shout at me if I haven't got it (it honestly seems way too easy:
there must be the trick ;))
Index: twisted/scripts/_twistd_unix.py
===================================================================
--- twisted/scripts/_twistd_unix.py (revision 27172)
+++ twisted/scripts/_twistd_unix.py (working copy)
@@ -82,7 +82,13 @@
sys.exit("Can't check status of PID %s from pidfile %s: %s" %
(pid, pidfile, why[1]))
else:
- sys.exit("""\
+ # If the PID in the file is our same PID, then we can remove the
+ # stale file
+ if os.getpid() == pid:
+ log.msg('Removing stale pidfile %s' % pidfile, isError=True)
+ os.remove(pidfile)
+ else:
+ sys.exit("""\
Another twistd server is running, PID %s\n
This could either be a previously started instance of your application or a
different application entirely. To start a new one, either run it in some other
_______________________________________________
Twisted-Python mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python