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

Guido van Rossum guido@python.org
Wed, 30 Oct 2002 09:08:44 -0500


> http://www.zope.org/Wikis/DevSite/Proposals/CleanShutdown
> 
> I would like to merge the implementation of this proposal with the
> trunk. The implementation is in toby-clean-shutdown-branch
> 
> Any objections?
> 
> (The patch currently applies cleanly to 2.6, and there are some
> minor conflicts applying it to the trunk. I do not propose adding
> applying it to the 2.6 maintenance branch)

FWIW, this looks right to me.

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?

--Guido van Rossum (home page: http://www.python.org/~guido/)