summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-11-03 12:38:13 -0400
committerLance Stout <lancestout@gmail.com>2010-11-03 12:38:13 -0400
commit0214db75451627c4e0d666e8567db24da31e4056 (patch)
tree972b269ea35ba27fe0ead67c993c9e84a77d5936 /sleekxmpp/xmlstream
parentffc6f031d9134015f16fadedc4e94e6f1a502b7b (diff)
downloadslixmpp-0214db75451627c4e0d666e8567db24da31e4056.tar.gz
slixmpp-0214db75451627c4e0d666e8567db24da31e4056.tar.bz2
slixmpp-0214db75451627c4e0d666e8567db24da31e4056.tar.xz
slixmpp-0214db75451627c4e0d666e8567db24da31e4056.zip
Catch exceptions for direct events.
Events triggered with direct=True will have exceptions caught. Note that all event handlers in a direct event will currently run in the same thread.
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index cc192715..d47557b7 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -535,13 +535,22 @@ class XMLStream(object):
name -- The name of the event to trigger.
data -- Data that will be passed to each event handler.
Defaults to an empty dictionary.
- direct -- Runs the event directly if True.
+ direct -- Runs the event directly if True, skipping the
+ event queue. All event handlers will run in the
+ same thread.
"""
for handler in self.__event_handlers.get(name, []):
if direct:
- handler[0](copy.copy(data))
+ try:
+ handler[0](copy.copy(data))
+ except Exception as e:
+ error_msg = 'Error processing event handler: %s'
+ logging.exception(error_msg % str(handler[0]))
+ if hasattr(data, 'exception'):
+ data.exception(e)
else:
self.event_queue.put(('event', handler, copy.copy(data)))
+
if handler[2]:
# If the handler is disposable, we will go ahead and
# remove it now instead of waiting for it to be
@@ -807,11 +816,6 @@ class XMLStream(object):
"""
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):
"""