Skip to content

Commit 7a85d84

Browse files
committed
Refactor _execute_request_loop to ensure status is published in finally block
1 parent da2d27f commit 7a85d84

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ipykernel/kernelbase.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,19 +472,19 @@ async def shell_main(self, subshell_id: str | None):
472472
async def _execute_request_loop(self, receive_stream: MemoryObjectReceiveStream):
473473
async with receive_stream:
474474
async for handler, (received_time, socket, idents, msg) in receive_stream:
475+
self.set_parent(idents, msg, channel="shell")
476+
self._publish_status("busy", "shell", parent=msg)
475477
try:
476478
if received_time < self._aborted_time:
477479
await self._send_abort_reply(socket, msg, idents)
478480
continue
479-
self.set_parent(idents, msg, channel="shell")
480-
self._publish_status("busy", "shell", parent=msg)
481481
result = handler(socket, idents, msg)
482482
if inspect.isawaitable(result):
483483
await result
484-
self.set_parent(idents, msg, channel="shell")
485-
self._publish_status("idle", "shell", parent=msg)
486484
except BaseException as e:
487485
self.log.exception("Execute request", exc_info=e)
486+
finally:
487+
self._publish_status("idle", "shell", parent=msg)
488488

489489
async def _process_shell(self, socket):
490490
# socket=None is valid if kernel subshells are not supported.

0 commit comments

Comments
 (0)