Skip to content

Commit 89b6201

Browse files
committed
Do not flush shell stream from wrong thread
1 parent 38ea703 commit 89b6201

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

ipykernel/kernelbase.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ async def do_one_iteration(self):
544544
This is now a coroutine
545545
"""
546546
# flush messages off of shell stream into the message queue
547-
if self.shell_stream:
547+
if self.shell_stream and not self._supports_kernel_subshells:
548548
self.shell_stream.flush()
549549
# process at most one shell message per iteration
550550
await self.process_one(wait=False)
@@ -673,9 +673,6 @@ async def shell_channel_thread_main(self, msg):
673673
except Exception:
674674
self.log.error("Invalid message", exc_info=True) # noqa: G201
675675

676-
if self.shell_stream:
677-
self.shell_stream.flush()
678-
679676
async def shell_main(self, subshell_id: str | None, msg):
680677
"""Handler of shell messages for a single subshell"""
681678
if self._supports_kernel_subshells:
@@ -741,7 +738,7 @@ def _publish_status(self, status, channel, parent=None):
741738
def _publish_status_and_flush(self, status, channel, stream, parent=None):
742739
"""send status on IOPub and flush specified stream to ensure reply is sent before handling the next reply"""
743740
self._publish_status(status, channel, parent)
744-
if stream and hasattr(stream, "flush"):
741+
if stream and hasattr(stream, "flush") and not self._supports_kernel_subshells:
745742
stream.flush(zmq.POLLOUT)
746743

747744
def _publish_debug_event(self, event):
@@ -1384,7 +1381,7 @@ def _abort_queues(self, subshell_id: str | None = None):
13841381

13851382
# flush streams, so all currently waiting messages
13861383
# are added to the queue
1387-
if self.shell_stream:
1384+
if self.shell_stream and not self._supports_kernel_subshells:
13881385
self.shell_stream.flush()
13891386

13901387
# Callback to signal that we are done aborting

0 commit comments

Comments
 (0)