#3270 defect closed fixed (fixed)
The XMPP example in Twisted.Words crashes if I stop it with Ctrl-C
Reported by: | jozilla | Owned by: | Jean-Paul Calderone |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | words | Keywords: | |
Cc: | Branch: |
branches/xmpp_client.py-3270-3
branch-diff, diff-cov, branch-cov, buildbot |
|
Author: | exarkun |
Description (last modified by )
The XMPP example (xmpp_client.py) in Twisted words throws an exception when I quit it with Ctrl-C:
Disconnected. Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/twisted/internet/posixbase.py", line 228, in mainLoop self.runUntilCurrent() File "/usr/lib/python2.5/site-packages/twisted/internet/base.py", line 561, in runUntilCurrent call.func(*call.args, **call.kw) File "/usr/lib/python2.5/site-packages/twisted/internet/base.py", line 414, in _continueSystemEvent callable(*args, **kw) File "/usr/lib/python2.5/site-packages/twisted/internet/base.py", line 375, in disconnectAll failure.Failure(main.CONNECTION_LOST)) --- <exception caught here> --- File "/usr/lib/python2.5/site-packages/twisted/python/log.py", line 48, in callWithLogger return callWithContext({"system": lp}, func, *args, **kw) File "/usr/lib/python2.5/site-packages/twisted/python/log.py", line 33, in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) File "/usr/lib/python2.5/site-packages/twisted/python/context.py", line 59, in callWithContext return self.currentContext().callWithContext(ctx, func, *args, **kw) File "/usr/lib/python2.5/site-packages/twisted/python/context.py", line 37, in callWithContext return func(*args,**kw) File "/usr/lib/python2.5/site-packages/twisted/internet/tcp.py", line 576, in connectionLost Connection.connectionLost(self, reason) File "/usr/lib/python2.5/site-packages/twisted/internet/tcp.py", line 416, in connectionLost protocol.connectionLost(reason) File "/usr/lib/python2.5/site-packages/twisted/words/xish/xmlstream.py", line 82, in connectionLost self.dispatch(self, STREAM_END_EVENT) File "/usr/lib/python2.5/site-packages/twisted/words/xish/utility.py", line 227, in dispatch self._eventObservers[(priority, event)].callback(object) File "/usr/lib/python2.5/site-packages/twisted/words/xish/utility.py", line 37, in callback methodwrapper(*args, **kwargs) File "/usr/lib/python2.5/site-packages/twisted/words/xish/utility.py", line 21, in __call__ self.method(*nargs, **nkwargs) File "xmpp_client.py", line 58, in disconnected reactor.stop() File "/usr/lib/python2.5/site-packages/twisted/internet/base.py", line 342, in stop raise RuntimeError, "can't stop reactor that isn't running" exceptions.RuntimeError: can't stop reactor that isn't running
I already posted this on the mailing list. Here is the comment by Ralph Meijer:
================= I haven't seen that behavior before, but I can confirm this happens. I poked around a bit with the example. It seems that the socket is closed before its factory is shut down. It might be that the reactor shutdown procedure has changed, so I think this behavior is the result of a bug, either in the example or somewhere else. =================
Change History (16)
comment:1 Changed 14 years ago by
Description: | modified (diff) |
---|
comment:2 Changed 14 years ago by
author: | → exarkun |
---|---|
Branch: | → branches/xmpp_client.py-3270 |
(In [23876]) Branching to 'xmpp_client.py-3270'
comment:3 Changed 14 years ago by
I'm not going to finish this now. radix convinced me that we should not introduce a new public API which is only capable of being used as twisted.internet.task.react
in this branch is capable of being used. Instead, #1490 should do something about this use-case and the examples should be updated to use that solution.
comment:4 Changed 14 years ago by
exarkun: could you expand a bit on why the current behaves as it does? I don't remember seeing such exceptions when the example code was written. I assume the idiom used in the example is not correct? Also, do you have some kind of work around that could be used until what you suggest should happen on #1490 has been completed?
comment:5 Changed 14 years ago by
It calls reactor.stop()
in its connection-lost handler. Also, C calls reactor.stop()
and disconnects everything. It needs to keep track of whether the reactor is already in the process of shutting down or not so that it can skip the call if it is. This is basically what I implemented in a general way in the branch.
comment:7 Changed 11 years ago by
Owner: | Jean-Paul Calderone deleted |
---|
comment:8 Changed 10 years ago by
Branch: | branches/xmpp_client.py-3270 → branches/xmpp_client.py-3270-2 |
---|
(In [34897]) Branching to 'xmpp_client.py-3270-2'
comment:9 Changed 10 years ago by
Branch: | branches/xmpp_client.py-3270-2 → branches/xmpp_client.py-3270-3 |
---|
(In [35697]) Branching to 'xmpp_client.py-3270-3'
comment:10 Changed 10 years ago by
Keywords: | review added |
---|---|
Owner: | set to Glyph |
Years later, #1490 is still open, so guess we'll go with this.
comment:11 Changed 10 years ago by
Keywords: | review removed |
---|---|
Owner: | changed from Glyph to Jean-Paul Calderone |
OK, I buy that.
- One (blocking) pyflakes:
doc/words/examples/xmpp_client.py:23: undefined name 'client_jid'
- It most likely deserves some documentation. Please open a bug if you're not tackling it there.
Thanks, please merge!
comment:13 Changed 10 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:14 Changed 10 years ago by
Would it be nice to also have a decorator-syntax version of this?
comment:15 follow-up: 16 Changed 10 years ago by
I don't know, would it? I feel like no. The decorator form (I am guessing, since "decorator-syntax version" is a long way away from a complete specification - if I guessed wrong it's your fault :) would take a perfectly reasonable Deferred-returning function and make it so you can only call it once, and only if the reactor is not running yet.
comment:16 Changed 10 years ago by
Replying to exarkun:
I don't know, would it? I feel like no. The decorator form (I am guessing, since "decorator-syntax version" is a long way away from a complete specification - if I guessed wrong it's your fault :) would take a perfectly reasonable Deferred-returning function and make it so you can only call it once, and only if the reactor is not running yet.
Yeah, that would be the naive implementation. I did implement this once: amphacks.util.mainpoint. It checks the function's __module__
and only runs it if it's in __main__
, in that implementation.
reformatting description