From ff57647679e1b20be56acaf90273e36f74d3601d Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Wed, 29 Mar 2023 11:50:08 -0500 Subject: [PATCH 1/2] Check if the iopub_channel is not closed before flushing it --- qtconsole/client.py | 4 ++++ qtconsole/frontend_widget.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/qtconsole/client.py b/qtconsole/client.py index 9306e859..df99009e 100644 --- a/qtconsole/client.py +++ b/qtconsole/client.py @@ -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.closed() + class QtKernelClient(QtKernelClientMixin, ThreadedKernelClient): """ A KernelClient that provides signals and slots. diff --git a/qtconsole/frontend_widget.py b/qtconsole/frontend_widget.py index 0978f2d3..d7d1134d 100644 --- a/qtconsole/frontend_widget.py +++ b/qtconsole/frontend_widget.py @@ -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 @@ -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() From 931b79bec46583104373c128c55a6c409841c8db Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 30 Mar 2023 09:53:07 -0500 Subject: [PATCH 2/2] Validate if stream is available when checking if channel is closed Co-authored-by: Min RK --- qtconsole/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/client.py b/qtconsole/client.py index df99009e..00ae9d63 100644 --- a/qtconsole/client.py +++ b/qtconsole/client.py @@ -47,7 +47,7 @@ def call_handlers(self, msg): def closed(self): """Check if the channel is closed.""" - return self.stream.closed() + return self.stream is None or self.stream.closed() class QtKernelClient(QtKernelClientMixin, ThreadedKernelClient):