summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-10-25 15:09:56 -0400
committerLance Stout <lancestout@gmail.com>2010-10-25 15:09:56 -0400
commit5bdcd9ef9d74d7921f5579086e6c6d94c0ac7deb (patch)
tree880d2d8f6db8232f1215fb4f6aa346faeaee07e5 /sleekxmpp/xmlstream
parent2eff35cc7a05ca0978befb6754921e1f6d8c270d (diff)
downloadslixmpp-1.0-Beta2.tar.gz
slixmpp-1.0-Beta2.tar.bz2
slixmpp-1.0-Beta2.tar.xz
slixmpp-1.0-Beta2.zip
Made exceptions work.sleek-1.0-Beta21.0-Beta2
Raising an XMPPError exception from an event handler now works, even if from a threaded handler. Added stream tests to verify. We should start using XMPPError, it really makes things simple!
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index e11497f2..ace93cc3 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -786,6 +786,23 @@ class XMLStream(object):
if unhandled:
stanza.unhandled()
+ def _threaded_event_wrapper(self, func, args):
+ """
+ Capture exceptions for event handlers that run
+ in individual threads.
+
+ Arguments:
+ func -- The event handler to execute.
+ args -- Arguments to the event handler.
+ """
+ try:
+ func(*args)
+ except Exception as e:
+ error_msg = 'Error processing event handler: %s'
+ logging.exception(error_msg % str(func))
+ if hasattr(args[0], 'exception'):
+ args[0].exception(e)
+
def _event_runner(self):
"""
Process the event queue and execute handlers.
@@ -825,14 +842,18 @@ class XMLStream(object):
func, threaded, disposable = handler
try:
if threaded:
- x = threading.Thread(name="Event_%s" % str(func),
- target=func,
- args=args)
+ x = threading.Thread(
+ name="Event_%s" % str(func),
+ target=self._threaded_event_wrapper,
+ args=(func, args))
x.start()
else:
func(*args)
- except:
- logging.exception('Error processing event handler: %s')
+ except Exception as e:
+ error_msg = 'Error processing event handler: %s'
+ logging.exception(error_msg % str(func))
+ if hasattr(args[0], 'exception'):
+ args[0].exception(e)
elif etype == 'quit':
logging.debug("Quitting event runner thread")
return False