Thanks for all the help.  We're going with addSystemEventTrigger for now, but we'll keep twistd in mind for future work.

Jason

On Fri, Feb 11, 2011 at 1:51 PM, Glyph Lefkowitz <glyph@twistedmatrix.com> wrote:

On Feb 11, 2011, at 11:55 AM, exarkun@twistedmatrix.com wrote:

> On 03:59 pm, jrennie@gmail.com wrote:
>> On Fri, Feb 11, 2011 at 10:01 AM, <exarkun@twistedmatrix.com> wrote:
>>> On Python 2.5 and earlier you won't be able to get Twisted's SIGCHLD
>>> handler using signal.getsignal.
>>
>> We're also moving to python 2.6 (the change is really Debian 5 to
>> Debian 6).
>> Should it would work in 2.6?
>
> I think so.
>>
>>> What sort of things do your signal handlers do?
>>
>> IIRC, the main thing is to shut down the web server (cherrypy) we're
>> running
>> in parallel with twisted.  We also have some disk-caching for stateful
>> signals which needs to ensure the cache file is up-to-date.
>
> For shutdown-type things, reactor.addSystemEventTrigger(phase,
> 'shutdown', f) might be better than getting into signal handlers (where
> phase is 'before', 'during', or 'after').


There's already a system event trigger already hooked up to the reactor: your main service's stopService call.  If your cherrypy webserver is wrapped up in an IService implementation in the service hierarchy constructed in your twistd plugin or tac file, you can just implement 'stopService' and not do any manual registration with event triggers.  This is really a better way to go in general, as it's easier for other API consumers to deal with such an object than using the global broadcasting mechanism in the reactor.

If you do want to manually add your own system event trigger, in most interesting cases you'll need to use the 'before' phase.  During 'before', Deferreds returned by event triggers are respected (i.e. the reactor keeps running as long as they haven't fired).  If you schedule one for 'during' or 'after', the event trigger really needs to do all of its work and complete it immediately (i.e. before returning).


_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python



--
Jason Rennie
Research Scientist, ITA Software
617-714-2645
http://www.itasoftware.com/