[Twisted-Python] signalfd

James Y Knight foom at fuhm.net
Wed Nov 3 23:51:02 EDT 2010

On Nov 3, 2010, at 10:23 PM, exarkun at twistedmatrix.com wrote:
> On 01:45 am, ndbecker2 at gmail.com wrote:
>> On modern linux, signalfd can be used to convert sigchld into an event 
>> on a
>> file descriptor.  Looks like just what is wanted for processProtocol.
> It does, indeed.  I'm not sure it's really worth bothering though.  Here 
> are the drawbacks of using signalfd():
>   - It only works on Linux
>   - It works differently on older versions of Linux than on newer 
> versions
>   - You still can't have another SIGCHLD handler installed that will 
> called (so it's not any more cooperative with other library code)

Another drawback is that spawned subprocesses will start with SIGCHLD blocked (because the sigprocmask is inherited across fork/exec, like SIG_IGN is, but unlike signal handlers), unless twisted adds a pthread_atfork handler (which there is no way to do from Python, so that'd have to be more custom C code). And even with that, system() would still remain broken, because system() inexplicably doesn't call atfork handlers on linux/glibc (notabug according to glibc maintainers).

Of course, the Twisted process API could unblock SIGCHLD itself before calling exec, but this would leave spawning a process with any other API (subprocess/etc) broken. Many programs will not react well to starting with SIGCHLD blocked.

Since Twisted just recently managed to make spawning subprocesses with non-Twisted APIs actually work right, it'd be quite poor to break that again.


More information about the Twisted-Python mailing list