I think that you should not put the sys.exit(1) call, after the reactor.stop() call. >From my very limited understanding of how Twisted reactor works, it could be done with something like:
statusCode = 1 #or whatever reactor.stop() in the method that stops the reactor and the exit call should be added where (after) the reactor is started: reactor.run() # this will be executed after reactor stops sys.exit(statusCode) Please, correct me if I write nonsense here. Pandelis Theodosiou On Fri, Sep 24, 2010 at 4:49 AM, David Cournapeau <courn...@gmail.com>wrote: > 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 > > _______________________________________________ > Twisted-Python mailing list > Twisted-Python@twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python >
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python