Skip to content

Commit

Permalink
Add option to EventManager to prevent printing
Browse files Browse the repository at this point in the history
  • Loading branch information
TNonet authored and Carreau committed Jun 2, 2023
1 parent 42ada4b commit 19c7bb1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions IPython/core/events.py
Expand Up @@ -26,7 +26,8 @@ class EventManager(object):
This API is experimental in IPython 2.0, and may be revised in future versions.
"""
def __init__(self, shell, available_events):

def __init__(self, shell, available_events, print_on_error=True):
"""Initialise the :class:`CallbackManager`.
Parameters
Expand All @@ -35,9 +36,12 @@ def __init__(self, shell, available_events):
The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
available_events
An iterable of names for callback events.
print_on_error:
A boolean flag to set whether the EventManager will print a warning which a event errors.
"""
self.shell = shell
self.callbacks = {n:[] for n in available_events}
self.print_on_error = print_on_error

def register(self, event, function):
"""Register a new event callback.
Expand Down Expand Up @@ -88,7 +92,8 @@ def trigger(self, event, *args, **kwargs):
try:
func(*args, **kwargs)
except (Exception, KeyboardInterrupt):
print("Error in callback {} (for {}):".format(func, event))
if self.print_on_error:
print("Error in callback {} (for {}):".format(func, event))
self.shell.showtraceback()

# event_name -> prototype mapping
Expand Down

0 comments on commit 19c7bb1

Please sign in to comment.