From afeadfcc84bfc6b2d5e6642943725e5b0833664f 2011-10-24 23:30:13 From: MinRK Date: 2011-10-24 23:30:13 Subject: [PATCH] various small fixes in qtconsole * Don't crash on second stdin request, because it's possible for multiple stdin_requests to come in succession (e.g. first was interrupted) * fix status=abort->aborted typo, and handle aborted executions properly closes gh-808 --- diff --git a/IPython/frontend/qt/console/frontend_widget.py b/IPython/frontend/qt/console/frontend_widget.py index ec5f7b4..df93310 100644 --- a/IPython/frontend/qt/console/frontend_widget.py +++ b/IPython/frontend/qt/console/frontend_widget.py @@ -308,6 +308,9 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): """ self.log.debug("execute: %s", msg.get('content', '')) info = self._request_info.get('execute') + # unset reading flag, because if execute finished, raw_input can't + # still be pending. + self._reading = False if info and info.id == msg['parent_header']['msg_id'] and \ info.kind == 'user' and not self._hidden: # Make sure that all output from the SUB channel has been processed @@ -326,7 +329,7 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): self._process_execute_ok(msg) elif status == 'error': self._process_execute_error(msg) - elif status == 'abort': + elif status == 'aborted': self._process_execute_abort(msg) self._show_interpreter_prompt_for_reply(msg) @@ -347,6 +350,9 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): def callback(line): self.kernel_manager.stdin_channel.input(line) + if self._reading: + self.log.debug("Got second input request, assuming first was interrupted.") + self._reading = False self._readline(msg['content']['prompt'], callback=callback) def _handle_kernel_died(self, since_last_heartbeat): @@ -464,10 +470,15 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin): def interrupt_kernel(self): """ Attempts to interrupt the running kernel. + + Also unsets _reading flag, to avoid runtime errors + if raw_input is called again. """ if self.custom_interrupt: + self._reading = False self.custom_interrupt_requested.emit() elif self.kernel_manager.has_kernel: + self._reading = False self.kernel_manager.interrupt_kernel() else: self._append_plain_text('Kernel process is either remote or ' diff --git a/IPython/frontend/qt/console/ipython_widget.py b/IPython/frontend/qt/console/ipython_widget.py index 53dc952..ea14490 100644 --- a/IPython/frontend/qt/console/ipython_widget.py +++ b/IPython/frontend/qt/console/ipython_widget.py @@ -372,7 +372,14 @@ class IPythonWidget(FrontendWidget): """ # Update the old prompt number if necessary. content = msg['content'] - previous_prompt_number = content['execution_count'] + # abort replies do not have any keys: + if content['status'] == 'aborted': + if self._previous_prompt_obj: + previous_prompt_number = self._previous_prompt_obj.number + else: + previous_prompt_number = 0 + else: + previous_prompt_number = content['execution_count'] if self._previous_prompt_obj and \ self._previous_prompt_obj.number != previous_prompt_number: block = self._previous_prompt_obj.block