Skip to content

Commit

Permalink
Merge 98adf08 into 6ce0c48
Browse files Browse the repository at this point in the history
  • Loading branch information
impact27 committed Nov 7, 2021
2 parents 6ce0c48 + 98adf08 commit f8342bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
8 changes: 6 additions & 2 deletions qtconsole/base_frontend_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,12 @@ def from_here(self, msg):

def include_output(self, msg):
"""Return whether we should include a given output message"""
if self._hidden:
return False
if msg['parent_header']:
# If parent message is from hidden execution, don't include it.
msg_id = msg['parent_header']['msg_id']
info = self._request_info['execute'].get(msg_id)
if info and info.hidden:
return False
from_here = self.from_here(msg)
if msg['msg_type'] == 'execute_input':
# only echo inputs not from here
Expand Down
30 changes: 20 additions & 10 deletions qtconsole/frontend_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def _lexer_default(self):
_CallTipRequest = namedtuple('_CallTipRequest', ['id', 'pos'])
_CompletionRequest = namedtuple('_CompletionRequest',
['id', 'code', 'pos'])
_ExecutionRequest = namedtuple('_ExecutionRequest', ['id', 'kind'])
_ExecutionRequest = namedtuple(
'_ExecutionRequest', ['id', 'kind', 'hidden'])
_local_kernel = False
_highlighter = Instance(FrontendHighlighter, allow_none=True)

Expand All @@ -166,7 +167,6 @@ def __init__(self, local_kernel=_local_kernel, *args, **kw):
self._bracket_matcher = BracketMatcher(self._control)
self._call_tip_widget = CallTipWidget(self._control)
self._copy_raw_action = QtWidgets.QAction('Copy (Raw Text)', None)
self._hidden = False
self._highlighter = FrontendHighlighter(self, lexer=self.lexer)
self._kernel_manager = None
self._kernel_client = None
Expand Down Expand Up @@ -283,8 +283,8 @@ def _execute(self, source, hidden):
See parent class :meth:`execute` docstring for full details.
"""
msg_id = self.kernel_client.execute(source, hidden)
self._request_info['execute'][msg_id] = self._ExecutionRequest(msg_id, 'user')
self._hidden = hidden
self._request_info['execute'][msg_id] = self._ExecutionRequest(
msg_id, 'user', hidden)
if not hidden:
self.executing.emit(source)

Expand Down Expand Up @@ -419,7 +419,8 @@ def _silent_exec_callback(self, expr, callback):
msg_id = self.kernel_client.execute('',
silent=True, user_expressions={ local_uuid:expr })
self._callback_dict[local_uuid] = callback
self._request_info['execute'][msg_id] = self._ExecutionRequest(msg_id, 'silent_exec_callback')
self._request_info['execute'][msg_id] = self._ExecutionRequest(
msg_id, 'silent_exec_callback', False)

def _handle_exec_callback(self, msg):
"""Execute `callback` corresponding to `msg` reply, after ``_silent_exec_callback``
Expand Down Expand Up @@ -455,7 +456,9 @@ def _handle_execute_reply(self, msg):
# still be pending.
self._reading = False
# Note: If info is NoneType, this is ignored
if info and info.kind == 'user' and not self._hidden:
if not info or info.hidden:
return
if info.kind == 'user':
# Make sure that all output from the SUB channel has been processed
# before writing a new prompt.
self.kernel_client.iopub_channel.flush()
Expand All @@ -476,10 +479,10 @@ def _handle_execute_reply(self, msg):
self._show_interpreter_prompt_for_reply(msg)
self.executed.emit(msg)
self._request_info['execute'].pop(msg_id)
elif info and info.kind == 'silent_exec_callback' and not self._hidden:
elif info.kind == 'silent_exec_callback':
self._handle_exec_callback(msg)
self._request_info['execute'].pop(msg_id)
elif info and not self._hidden:
else:
raise RuntimeError("Unknown handler for %s" % info.kind)

def _handle_error(self, msg):
Expand All @@ -491,7 +494,9 @@ def _handle_input_request(self, msg):
""" Handle requests for raw_input.
"""
self.log.debug("input: %s", msg.get('content', ''))
if self._hidden:
msg_id = msg['parent_header']['msg_id']
info = self._request_info['execute'].get(msg_id)
if info and info.hidden:
raise RuntimeError('Request for raw input during hidden execution.')

# Make sure that all output from the SUB channel has been processed
Expand Down Expand Up @@ -564,7 +569,12 @@ def _handle_shutdown_reply(self, msg):
"""
self.log.debug("shutdown: %s", msg.get('content', ''))
restart = msg.get('content', {}).get('restart', False)
if not self._hidden and not self.from_here(msg):
if msg['parent_header']:
msg_id = msg['parent_header']['msg_id']
info = self._request_info['execute'].get(msg_id)
if info and info.hidden:
return
if not self.from_here(msg):
# got shutdown reply, request came from session other than ours
if restart:
# someone restarted the kernel, handle it
Expand Down
8 changes: 7 additions & 1 deletion qtconsole/jupyter_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def __init__(self, *args, **kw):

# Initialize language name.
self.language_name = None
self._prompt_requested = False

#---------------------------------------------------------------------------
# 'BaseFrontendMixin' abstract interface
Expand Down Expand Up @@ -183,6 +184,7 @@ def _handle_execute_reply(self, msg):
msg_id = msg['parent_header'].get('msg_id')
info = self._request_info['execute'].get(msg_id)
if info and info.kind == 'prompt':
self._prompt_requested = False
content = msg['content']
if content['status'] == 'aborted':
self._show_interpreter_prompt()
Expand Down Expand Up @@ -371,8 +373,12 @@ def _show_interpreter_prompt(self, number=None):
"""
# If a number was not specified, make a prompt number request.
if number is None:
if self._prompt_requested:
# Already asked for prompt, avoid multiple prompts.
return
self._prompt_requested = True
msg_id = self.kernel_client.execute('', silent=True)
info = self._ExecutionRequest(msg_id, 'prompt')
info = self._ExecutionRequest(msg_id, 'prompt', False)
self._request_info['execute'][msg_id] = info
return

Expand Down

0 comments on commit f8342bb

Please sign in to comment.