Skip to content

Commit

Permalink
various small fixes in qtconsole
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
minrk committed Oct 24, 2011
1 parent 2506258 commit afeadfc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 12 additions & 1 deletion IPython/frontend/qt/console/frontend_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ def _handle_execute_reply(self, msg):
"""
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
Expand All @@ -326,7 +329,7 @@ def _handle_execute_reply(self, msg):
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)
Expand All @@ -347,6 +350,9 @@ def _handle_input_request(self, msg):

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):
Expand Down Expand Up @@ -464,10 +470,15 @@ def execute_file(self, path, hidden=False):

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 '
Expand Down
9 changes: 8 additions & 1 deletion IPython/frontend/qt/console/ipython_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,14 @@ def _show_interpreter_prompt_for_reply(self, msg):
"""
# 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
Expand Down

0 comments on commit afeadfc

Please sign in to comment.