SimpleXMLRPCServer daemon

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Feb 1 11:25:15 CET 2010


Gabriel Genellina wrote:
> 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)
>
see also http://code.activestate.com/recipes/278731/

JM



More information about the Python-list mailing list