[Zope-Coders] extra-clean shutdown, signal handling

Toby Dickenson tdickenson@geminidataloggers.com
Wed, 30 Oct 2002 15:36:16 +0000


On Wednesday 30 October 2002 2:08 pm, Guido van Rossum wrote:

> BTW I'd like to refactor zdaemon and ZEO/start.py to be more
> object-oriented.  I imagine that zdaemon could be replaced by a class
> that implements the typical control flow: check args, usage/help
> message, exit, daemonize, write pid file, setup signal handlers,
> initialization, main loop, cleanup.  Then ZEO/start.py (and a few
> other scripts we maintain just like it) can extend the various phases
> to tweak them.  The instance would be a good place to hold on to
> command line options, "stop" flags set by signal handlers, and other
> objects created as part of the initialization (e.g. storages).
>
> I'd also like to get rid of the following zdaemon behavior: as part of
> 'daemonizing", it restarts your program from the beginning.  This can
> cause tricky bugs.  E.g. we just tracked one down that was like this:
>
>     write_pidfile(pid_file)
>     if using_zdaemon:
>         zdaemon.run(..., pid_file)
>
> This ended up writing the child process's pid to the pid_file, rather
> than the zdaemon process manager's pid.  Does anyone understand why
> zdaemon does fork+fork+exec rather than just fork+fork?

That all sounds good to me. A candidate for the python standard library?