diff --git a/IPython/core/events.py b/IPython/core/events.py index 1405682..6ebd790 100644 --- a/IPython/core/events.py +++ b/IPython/core/events.py @@ -86,7 +86,7 @@ class EventManager(object): for func in self.callbacks[event][:]: try: func(*args, **kwargs) - except Exception: + except (Exception, KeyboardInterrupt): print("Error in callback {} (for {}):".format(func, event)) self.shell.showtraceback() diff --git a/IPython/core/tests/test_events.py b/IPython/core/tests/test_events.py index 37edd91..6bc4d88 100644 --- a/IPython/core/tests/test_events.py +++ b/IPython/core/tests/test_events.py @@ -51,6 +51,12 @@ class CallbackTests(unittest.TestCase): with tt.AssertPrints("Error in callback"): self.em.trigger('ping_received') + def test_cb_keyboard_interrupt(self): + cb = Mock(side_effect=KeyboardInterrupt) + self.em.register('ping_received', cb) + with tt.assertPrints("Error in callback"): + self.em.trigger('ping_received') + def test_unregister_during_callback(self): invoked = [False] * 3