[Twisted-Python] sigchld

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Fri Feb 11 08:01:10 MST 2011


On 02:27 pm, jrennie at gmail.com wrote:
>I'm in the process of porting code from Twisted 8.1 to 10.1 which 
>needed
>some custom signal handling code.  Twisted 8.1's approach to signal 
>handling
>was (as far as we could tell) too monolithic, so we chose
>"installSignalHandlers=False" and wrote our own signal handling code,
>installing reactor._handleSigchld so that spawnProcess would work.  Of
>course, we have to change this now since #733 was fixed (
>http://twistedmatrix.com/trac/ticket/733).
>
>IIUC, (and please correct if I don't) the SIGCHLD handler installation 
>is
>performed by twisted.internet.posixbase.PosixReactorBase._handleSignals 
>(the
>"if platformType == 'posix':" block).  So, one option would be to run 
>that
>code while still using "installSignalHandlers=False".
>
>I'm wondering if there's a better way.  What if I were to let Twisted
>install signal handlers, but run my own signal handling code after the
>reactor starts (using callLater(0,...)) that installs "super" handlers 
>which
>calls the Twisted handler along with any other handlers I want to run. 
>I'd
>use signal.getsignal to get a reference to the Twisted handler(s). 
>Might
>this work?  Or, is there an obvious flaw?  In particular, can I get the
>SIGCHLD handler using signal.getsignal, then call it via my "super" 
>handler?
>I don't need to do any special handling of SIGCHLD, so I could just 
>leave
>that signal handler alone.

On Python 2.5 and earlier you won't be able to get Twisted's SIGCHLD 
handler using signal.getsignal.

For other signal handlers, signal.getsignal should work fine.

I also think it would be good for the reactor to not do so much with 
signals (aside from SIGCHLD), or provide a better public interface for 
controlling what it does.

What sort of things do your signal handlers do?

Jean-Paul




More information about the Twisted-Python mailing list