No subject


Sun Apr 26 08:47:01 EDT 2009


    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 <cournape at 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 at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>

--00151748dbc255864b0490ff68e3
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I think that you should not put the sys.exit(1) call, after the reactor.sto=
p() call.<br>From my very limited understanding of how Twisted reactor work=
s, it could be done with something like:<br><br>=C2=A0=C2=A0=C2=A0 statusCo=
de =3D 1 #or whatever<br>
=C2=A0=C2=A0=C2=A0 reactor.stop()<br><br>in the method that stops the react=
or<br><br>and the exit call should be added where (after) the reactor is st=
arted:<br><br>=C2=A0 =C2=A0 reactor.run()<br>=C2=A0=C2=A0=C2=A0 # this will=
 be executed after reactor stops<br>
=C2=A0=C2=A0=C2=A0 sys.exit(statusCode)<br><br>Please, correct me if I writ=
e nonsense here. <br><br>Pandelis Theodosiou<br><br><div class=3D"gmail_quo=
te">On Fri, Sep 24, 2010 at 4:49 AM, David Cournapeau <span dir=3D"ltr">&lt=
;<a href=3D"mailto:cournape at gmail.com">cournape at gmail.com</a>&gt;</span> wr=
ote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; borde=
r-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi,<br>
<br>
I have a program run through twistd, and would like to exit with a non<br>
zero status code on some error. I have a callback which stops the<br>
reactor and then sys.exit(some_value), but twistd still seems to catch<br>
the SystemExit exception after calling for reactor.stop():<br>
<br>
Unhandled error in Deferred:<br>
Traceback (most recent call last):<br>
 =C2=A0File &quot;/home/david/local/lib/python2.6/site-packages/twisted/int=
ernet/base.py&quot;,<br>
line 1031, in connectionFailed<br>
 =C2=A0 =C2=A0self.factory.clientConnectionFailed(self, reason)<br>
 =C2=A0File &quot;/home/david/local/lib/python2.6/site-packages/twisted/web=
/client.py&quot;,<br>
line 350, in clientConnectionFailed<br>
 =C2=A0 =C2=A0self.deferred.errback(reason)<br>
 =C2=A0File &quot;/home/david/local/lib/python2.6/site-packages/twisted/int=
ernet/defer.py&quot;,<br>
line 307, in errback<br>
 =C2=A0 =C2=A0self._startRunCallbacks(fail)<br>
 =C2=A0File &quot;/home/david/local/lib/python2.6/site-packages/twisted/int=
ernet/defer.py&quot;,<br>
line 354, in _startRunCallbacks<br>
 =C2=A0 =C2=A0self._runCallbacks()<br>
--- &lt;exception caught here&gt; ---<br>
 =C2=A0File &quot;/home/david/local/lib/python2.6/site-packages/twisted/int=
ernet/defer.py&quot;,<br>
line 371, in _runCallbacks<br>
 =C2=A0 =C2=A0self.result =3D callback(self.result, *args, **kw)<br>
 =C2=A0File &quot;scripts/tests/run_tests.py&quot;, line 69, in exit_on_err=
or<br>
 =C2=A0 =C2=A0sys.exit(1)<br>
exceptions.SystemExit: 1<br>
<br>
What&#39;s the correct way of doing this ?<br>
<br>
cheers,<br>
<br>
David<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href=3D"mailto:Twisted-Python at twistedmatrix.com">Twisted-Python at twistedm=
atrix.com</a><br>
<a href=3D"http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python=
" target=3D"_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twist=
ed-python</a><br>
</blockquote></div><br><div style=3D"visibility: hidden; display: inline;" =
id=3D"avg_ls_inline_popup"></div><style type=3D"text/css">#avg_ls_inline_po=
pup {  position:absolute;  z-index:9999;  padding: 0px 0px;  margin-left: 0=
px;  margin-top: 0px;  width: 240px;  overflow: hidden;  word-wrap: break-w=
ord;  color: black;  font-size: 10px;  text-align: left;  line-height: 13px=
;}</style>

--00151748dbc255864b0490ff68e3--



More information about the Twisted-Python mailing list