[Twisted-Python] sigchld

Glyph Lefkowitz glyph at twistedmatrix.com
Fri Feb 11 11:51:00 MST 2011


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

> On 03:59 pm, jrennie at gmail.com wrote:
>> On Fri, Feb 11, 2011 at 10:01 AM, <exarkun at 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).





More information about the Twisted-Python mailing list