##// END OF EJS Templates
Add option to EventManager to prevent printing (#14076)...
Matthias Bussonnier -
r28314:ee0bc157 merge
parent child Browse files
Show More
@@ -26,7 +26,8 b' class EventManager(object):'
26 26
27 27 This API is experimental in IPython 2.0, and may be revised in future versions.
28 28 """
29 def __init__(self, shell, available_events):
29
30 def __init__(self, shell, available_events, print_on_error=True):
30 31 """Initialise the :class:`CallbackManager`.
31 32
32 33 Parameters
@@ -35,9 +36,12 b' class EventManager(object):'
35 36 The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
36 37 available_events
37 38 An iterable of names for callback events.
39 print_on_error:
40 A boolean flag to set whether the EventManager will print a warning which a event errors.
38 41 """
39 42 self.shell = shell
40 43 self.callbacks = {n:[] for n in available_events}
44 self.print_on_error = print_on_error
41 45
42 46 def register(self, event, function):
43 47 """Register a new event callback.
@@ -88,7 +92,8 b' class EventManager(object):'
88 92 try:
89 93 func(*args, **kwargs)
90 94 except (Exception, KeyboardInterrupt):
91 print("Error in callback {} (for {}):".format(func, event))
95 if self.print_on_error:
96 print("Error in callback {} (for {}):".format(func, event))
92 97 self.shell.showtraceback()
93 98
94 99 # event_name -> prototype mapping
General Comments 0
You need to be logged in to leave comments. Login now