GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add option to EventManager to prevent printing (#14076) · ipython/ipython@ee0bc15

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • IPython/core
    • events.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎IPython/core/events.py‎

Copy file name to clipboardExpand all lines: IPython/core/events.py
+7-2Lines 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 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.