SimpleXMLRPCServer daemon
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Jan 29 15:28:24 EST 2010
En Fri, 29 Jan 2010 12:54:23 -0300, Thomas Allen <thomasmallen at gmail.com>
escribió:
> I have a script that runs an instance of SimpleXMLRPCServer and in
> general it works as expected. In its __del__, it is supposed to clean
> up its PID file (written on boot). I have two problems with this
> server instance: The first is that tt doesn't always clean up its PID
> file; is there a more reliable way to do this than how I am currently?
> The second is that when it does crash, I don't know about it...what
> would be sufficient as a "keep-alive" script to restart it? I suppose
> I could use something like EventMachine (already installed on my
> server) to watch the PID file if it were deleted reliably.
I agree with the recommendation of using some daemon library; doing it
right is better left to the experts :)
But if you can't or don't want to alter your code so much, I suggest:
- use atexit.register, instead of __del__, to delete the PID file
- keep a lock on the pid file; if a second instance is able to write to
it, it means it's an orphan from a previous, aborted run. (Checking
whether a process with such pid exists is not enough - pids are recycled
rather fast)
--
Gabriel Genellina
More information about the Python-list
mailing list