diff --git a/qtconsole/client.py b/qtconsole/client.py index 9306e859..00ae9d63 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 is None or 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()