diff --git a/IPython/terminal/ptshell.py b/IPython/terminal/ptshell.py index 85dbe22..305a782 100644 --- a/IPython/terminal/ptshell.py +++ b/IPython/terminal/ptshell.py @@ -253,8 +253,8 @@ class TerminalInteractiveShell(InteractiveShell): mouse_support=self.mouse_support, **self._layout_options() ) - self.pt_cli = CommandLineInterface(self._app, - eventloop=create_eventloop(self.inputhook)) + self._eventloop = create_eventloop(self.inputhook) + self.pt_cli = CommandLineInterface(self._app, eventloop=self._eventloop) def _make_style_from_name(self, name): """ @@ -384,6 +384,9 @@ class TerminalInteractiveShell(InteractiveShell): break except KeyboardInterrupt: print("\nKeyboardInterrupt escaped interact()\n") + + if hasattr(self, '_eventloop'): + self._eventloop.close() _inputhook = None def inputhook(self, context):