From d6033cd1ec53183559c4777e9ee4c0027779fd1f Mon Sep 17 00:00:00 2001 From: rle Date: Wed, 20 Aug 2025 00:09:13 +0700 Subject: [PATCH 1/3] fix: add flag to allow to stop to avoid stopping too early after restart kernel and run all cells --- jupyter_client/client.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/jupyter_client/client.py b/jupyter_client/client.py index 67c44600..6cd92cd7 100644 --- a/jupyter_client/client.py +++ b/jupyter_client/client.py @@ -540,6 +540,7 @@ async def _async_execute_interactive( stdin_socket = None # wait for output and redisplay it + can_stop = False while True: if timeout is not None: timeout = max(0, deadline - time.monotonic()) @@ -564,12 +565,14 @@ async def _async_execute_interactive( continue output_hook(msg) - # stop on idle - if ( - msg["header"]["msg_type"] == "status" - and msg["content"]["execution_state"] == "idle" - ): - break + state = msg["content"]["execution_state"] + if msg["header"]["msg_type"] == "status": + # allow to stop + if state == 'busy': + can_stop = True + # stop on idle + if state == 'idle' and can_stop: + break # output is done, get the reply if timeout is not None: From e40d44ee9ceefc31458c7a1c0aef53f1320fe658 Mon Sep 17 00:00:00 2001 From: rle Date: Wed, 20 Aug 2025 01:57:57 +0700 Subject: [PATCH 2/3] fix: syntax --- jupyter_client/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_client/client.py b/jupyter_client/client.py index 6cd92cd7..e768e00a 100644 --- a/jupyter_client/client.py +++ b/jupyter_client/client.py @@ -565,8 +565,8 @@ async def _async_execute_interactive( continue output_hook(msg) - state = msg["content"]["execution_state"] if msg["header"]["msg_type"] == "status": + state = msg["content"]["execution_state"] # allow to stop if state == 'busy': can_stop = True From 140c7f4a69aeae35f1f6df36a9620263e703b75c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 19 Aug 2025 18:59:46 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- jupyter_client/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jupyter_client/client.py b/jupyter_client/client.py index e768e00a..423a8d62 100644 --- a/jupyter_client/client.py +++ b/jupyter_client/client.py @@ -568,10 +568,10 @@ async def _async_execute_interactive( if msg["header"]["msg_type"] == "status": state = msg["content"]["execution_state"] # allow to stop - if state == 'busy': - can_stop = True + if state == "busy": + can_stop = True # stop on idle - if state == 'idle' and can_stop: + if state == "idle" and can_stop: break # output is done, get the reply