[Twisted-Python] How to exit a twistd program with a status code ?

David Cournapeau cournape at gmail.com
Thu Sep 23 21:49:24 EDT 2010


Hi,

I have a program run through twistd, and would like to exit with a non
zero status code on some error. I have a callback which stops the
reactor and then sys.exit(some_value), but twistd still seems to catch
the SystemExit exception after calling for reactor.stop():

Unhandled error in Deferred:
Traceback (most recent call last):
  File "/home/david/local/lib/python2.6/site-packages/twisted/internet/base.py",
line 1031, in connectionFailed
    self.factory.clientConnectionFailed(self, reason)
  File "/home/david/local/lib/python2.6/site-packages/twisted/web/client.py",
line 350, in clientConnectionFailed
    self.deferred.errback(reason)
  File "/home/david/local/lib/python2.6/site-packages/twisted/internet/defer.py",
line 307, in errback
    self._startRunCallbacks(fail)
  File "/home/david/local/lib/python2.6/site-packages/twisted/internet/defer.py",
line 354, in _startRunCallbacks
    self._runCallbacks()
--- <exception caught here> ---
  File "/home/david/local/lib/python2.6/site-packages/twisted/internet/defer.py",
line 371, in _runCallbacks
    self.result = callback(self.result, *args, **kw)
  File "scripts/tests/run_tests.py", line 69, in exit_on_error
    sys.exit(1)
exceptions.SystemExit: 1

What's the correct way of doing this ?

cheers,

David



More information about the Twisted-Python mailing list