Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the iopub channel is not closed before flushing it #574

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions qtconsole/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def call_handlers(self, msg):
# Emit the generic signal.
self.message_received.emit(msg)

def closed(self):
"""Check if the channel is closed."""
return self.stream is None or self.stream.closed()


class QtKernelClient(QtKernelClientMixin, ThreadedKernelClient):
""" A KernelClient that provides signals and slots.
Expand Down
6 changes: 4 additions & 2 deletions qtconsole/frontend_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ def _handle_execute_reply(self, msg):
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()
if not self.kernel_client.iopub_channel.closed():
self.kernel_client.iopub_channel.flush()

# Reset the ANSI style information to prevent bad text in stdout
# from messing up our colors. We're not a true terminal so we're
Expand Down Expand Up @@ -505,7 +506,8 @@ def _handle_input_request(self, msg):

# Make sure that all output from the SUB channel has been processed
# before entering readline mode.
self.kernel_client.iopub_channel.flush()
if not self.kernel_client.iopub_channel.closed():
self.kernel_client.iopub_channel.flush()

def callback(line):
self._finalize_input_request()
Expand Down