##// END OF EJS Templates
Add option to EventManager to prevent printing
Tim Nonet -
Show More
@@ -26,7 +26,8 b' class EventManager(object):'
26
26
27 This API is experimental in IPython 2.0, and may be revised in future versions.
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 """Initialise the :class:`CallbackManager`.
31 """Initialise the :class:`CallbackManager`.
31
32
32 Parameters
33 Parameters
@@ -35,9 +36,12 b' class EventManager(object):'
35 The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
36 The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
36 available_events
37 available_events
37 An iterable of names for callback events.
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 self.shell = shell
42 self.shell = shell
40 self.callbacks = {n:[] for n in available_events}
43 self.callbacks = {n:[] for n in available_events}
44 self.print_on_error = print_on_error
41
45
42 def register(self, event, function):
46 def register(self, event, function):
43 """Register a new event callback.
47 """Register a new event callback.
@@ -88,7 +92,8 b' class EventManager(object):'
88 try:
92 try:
89 func(*args, **kwargs)
93 func(*args, **kwargs)
90 except (Exception, KeyboardInterrupt):
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 self.shell.showtraceback()
97 self.shell.showtraceback()
93
98
94 # event_name -> prototype mapping
99 # event_name -> prototype mapping
General Comments 0
You need to be logged in to leave comments. Login now