AW: Re: [Twisted-Python] Can a deferred catch a segmentation fault ?

Andreas Kostyrka andreas at
Thu Sep 20 13:50:44 EDT 2007

Setting up such signal handler wouldn't be trivial (as in unsafe). The "normal" thing in such a situation is to longjmp (in C) or to let the process to die (which is the safe thing to do),

Now presuming that you cannot fix the segfaults (which as sad it sounds is quite common when using commercial 3rd party DLLs. Practice shows that being even a huge customer often get a quick turn around on bugs especially if its a hard to reproduce random crash. Driver DLLs for hardware costing $10K upwards come to mind, *shudder*), your only safe way is to isolate the driver usage into a seperate process. (If you are unlucky not even that is enough because some hardware gets stuck in a state that needs manual cold reseting, but let's be optimistic here).

With a seperate process, you can restart it should it die.


-- Ursprüngl. Mitteil. --
Betreff:	Re: [Twisted-Python] Can a deferred catch a segmentation fault?
Von:	Jean-Paul Calderone <exarkun at>
Datum:		20.09.2007 16:34

On Thu, 20 Sep 2007 09:14:11 -0700, "Gerald John M. Manipon" <geraldjohn.m.manipon at> wrote:
>I'm using deferToThread to run some python code which may or may not
>be safe.  In particular, the code may load some modules that could
>seg fault.  In this case, deferToThread won't work and the python
>process will bomb so I was wondering what Defer strategy I could
>use to handle this situation:

Deferreds don't do anything which will directly help in this situation.
If your process receives a signal for which the action is to exit, then
it will exit.  If you want, you can change the action associated with
certain signals (even SIGSEGV).  What action you *do* cause to happen
in such a case is independent of Deferreds.  You could, conceivably,
turn a segfault into an exception and then errback a Deferred.  However,
I wouldn't actually recommend this.  I would recommend not using software
which segfaults, fixing segfault bugs you find in software you are
using, and having comprehensive unit tests so that if something is
going to segfault, it does so during the course of development, not
on whatever server or client machines your software is deployed to.


Twisted-Python mailing list
Twisted-Python at

More information about the Twisted-Python mailing list