def emit(self, *args, **kwargs):
'''
Emit the event with the given positional and keyword arguments.
Returns a dict mapping event listeners to their results, or an exception
instance if calling the listener raised one.
'''
results = {}
# kwargs['__event__'] = self
for listener in self._listeners.values():
if isinstance(listener, (weakref.ReferenceType, BoundMethodWeakref)):
listener = listener()
if listener is None:
# This shouldn't happen, but we need to guard for it.
continue
try:
results[listener] = listener(*args, **kwargs)
except Exception as e:
if self._abort_on_error:
raise
results[listener] = e
print("error in listener: %s".format(listener))
import traceback
traceback.print_exc()
return results
评论列表
文章目录