Skip to content

Commit 7603443

Browse files
[Bugfix] Set shell idle when message skipped by "should_handle" in "dispatch_shell" (#1395)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3c96ba2 commit 7603443

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

ipykernel/kernelbase.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,7 @@ async def process_control(self, msg):
331331

332332
sys.stdout.flush()
333333
sys.stderr.flush()
334-
self._publish_status("idle", "control")
335-
# flush to ensure reply is sent
336-
if self.control_stream:
337-
self.control_stream.flush(zmq.POLLOUT)
334+
self._publish_status_and_flush("idle", "control", self.control_stream)
338335

339336
def should_handle(self, stream, msg, idents):
340337
"""Check whether a shell-channel message should be handled
@@ -370,11 +367,7 @@ async def dispatch_shell(self, msg):
370367
# Only abort execute requests
371368
if self._aborting and msg_type == "execute_request":
372369
self._send_abort_reply(self.shell_stream, msg, idents)
373-
self._publish_status("idle", "shell")
374-
# flush to ensure reply is sent before
375-
# handling the next request
376-
if self.shell_stream:
377-
self.shell_stream.flush(zmq.POLLOUT)
370+
self._publish_status_and_flush("idle", "shell", self.shell_stream)
378371
return
379372

380373
# Print some info about this message and leave a '--->' marker, so it's
@@ -384,6 +377,7 @@ async def dispatch_shell(self, msg):
384377
self.log.debug(" Content: %s\n --->\n ", msg["content"])
385378

386379
if not self.should_handle(self.shell_stream, msg, idents):
380+
self._publish_status_and_flush("idle", "shell", self.shell_stream)
387381
return
388382

389383
handler = self.shell_handlers.get(msg_type, None)
@@ -412,11 +406,7 @@ async def dispatch_shell(self, msg):
412406

413407
sys.stdout.flush()
414408
sys.stderr.flush()
415-
self._publish_status("idle", "shell")
416-
# flush to ensure reply is sent before
417-
# handling the next request
418-
if self.shell_stream:
419-
self.shell_stream.flush(zmq.POLLOUT)
409+
self._publish_status_and_flush("idle", "shell", self.shell_stream)
420410

421411
def pre_handler_hook(self):
422412
"""Hook to execute before calling message handler"""
@@ -603,6 +593,12 @@ def _publish_status(self, status, channel, parent=None):
603593
ident=self._topic("status"),
604594
)
605595

596+
def _publish_status_and_flush(self, status, channel, stream, parent=None):
597+
"""send status on IOPub and flush specified stream to ensure reply is sent before handling the next reply"""
598+
self._publish_status(status, channel, parent)
599+
if stream:
600+
stream.flush(zmq.POLLOUT)
601+
606602
def _publish_debug_event(self, event):
607603
if not self.session:
608604
return

0 commit comments

Comments
 (0)