[Twisted-Python] Can a deferred catch a segmentation fault?
Hi, 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: from twisted.internet import threads, reactor def segFaultFunc(): import binning #this will seg fault return True def myCb(res): print "Got", res reactor.stop() d = threads.deferToThread(segFaultFunc) d.addCallback(myCb) reactor.run() Any help on this is greatly appreciated. Thanks, Gerald
On Thu, 20 Sep 2007 09:14:11 -0700, "Gerald John M. Manipon" <geraldjohn.m.manipon@jpl.nasa.gov> wrote:
Hi,
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. Jean-Paul
Thanks for the responses. Ed, AsynQueue is exactly what I'm looking for! Is it possible for me to test it out? Gerald Gerald John M. Manipon wrote:
Hi,
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:
from twisted.internet import threads, reactor
def segFaultFunc(): import binning #this will seg fault return True
def myCb(res): print "Got", res reactor.stop()
d = threads.deferToThread(segFaultFunc) d.addCallback(myCb)
reactor.run()
Any help on this is greatly appreciated.
Thanks,
Gerald
participants (2)
-
Gerald John M. Manipon
-
Jean-Paul Calderone