Skip to content

Commit ee0bc15

Browse files
authored
Add option to EventManager to prevent printing (#14076)
I would love to be able to turn off this print statement as it regularly get in the way of nice error formatting.
2 parents 1d4e184 + 19c7bb1 commit ee0bc15

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

IPython/core/events.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class EventManager(object):
2626
2727
This API is experimental in IPython 2.0, and may be revised in future versions.
2828
"""
29-
def __init__(self, shell, available_events):
29+
30+
def __init__(self, shell, available_events, print_on_error=True):
3031
"""Initialise the :class:`CallbackManager`.
3132
3233
Parameters
@@ -35,9 +36,12 @@ def __init__(self, shell, available_events):
3536
The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
3637
available_events
3738
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.
3841
"""
3942
self.shell = shell
4043
self.callbacks = {n:[] for n in available_events}
44+
self.print_on_error = print_on_error
4145

4246
def register(self, event, function):
4347
"""Register a new event callback.
@@ -88,7 +92,8 @@ def trigger(self, event, *args, **kwargs):
8892
try:
8993
func(*args, **kwargs)
9094
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))
9297
self.shell.showtraceback()
9398

9499
# event_name -> prototype mapping

0 commit comments

Comments
 (0)