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

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


> > 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?

Let's first solve this in the context of Zope.  If it works there I'd
be happy to consider it for the Python standard library -- but the
requirements there may be different because we can assume less about
the application domain.

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