From 970a08d5acd69882873c3b6d0462261701cd098b 2016-05-12 12:36:34 From: Thomas Kluyver Date: 2016-05-12 12:36:34 Subject: [PATCH] Explicitly close prompt_toolkit event loop after running This is recommended, see jonathanslenders/python-prompt-toolkit#287. Normally it won't matter, because we close it just before the process exits, but if someone is embedding it repeatedly it could leave pipes lingering. --- diff --git a/IPython/terminal/ptshell.py b/IPython/terminal/ptshell.py index 3a7e9a6..7751a05 100644 --- a/IPython/terminal/ptshell.py +++ b/IPython/terminal/ptshell.py @@ -251,8 +251,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): """ @@ -383,6 +383,8 @@ class TerminalInteractiveShell(InteractiveShell): except KeyboardInterrupt: print("\nKeyboardInterrupt escaped interact()\n") + self._eventloop.close() + _inputhook = None def inputhook(self, context): if self._inputhook is not None: