Skip to content

Commit ae8b540

Browse files
committed
Debug
1 parent d8df24d commit ae8b540

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

tests/test_subshells.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111
from jupyter_client.blocking.client import BlockingKernelClient
1212

13-
from .utils import TIMEOUT, get_replies, get_reply, new_kernel
13+
from .utils import TIMEOUT, assemble_output, get_replies, get_reply, new_kernel
1414

1515
# Helpers
1616

@@ -20,6 +20,7 @@ def create_subshell_helper(kc: BlockingKernelClient):
2020
kc.control_channel.send(msg)
2121
msg_id = msg["header"]["msg_id"]
2222
reply = get_reply(kc, msg_id, TIMEOUT, channel="control")
23+
assemble_output(kc.get_iopub_msg) # wait for idle
2324
return reply["content"]
2425

2526

@@ -28,6 +29,7 @@ def delete_subshell_helper(kc: BlockingKernelClient, subshell_id: str):
2829
kc.control_channel.send(msg)
2930
msg_id = msg["header"]["msg_id"]
3031
reply = get_reply(kc, msg_id, TIMEOUT, channel="control")
32+
assemble_output(kc.get_iopub_msg) # wait for idle
3133
return reply["content"]
3234

3335

@@ -36,6 +38,7 @@ def list_subshell_helper(kc: BlockingKernelClient):
3638
kc.control_channel.send(msg)
3739
msg_id = msg["header"]["msg_id"]
3840
reply = get_reply(kc, msg_id, TIMEOUT, channel="control")
41+
assemble_output(kc.get_iopub_msg) # wait for idle
3942
return reply["content"]
4043

4144

@@ -49,20 +52,8 @@ def execute_request(kc: BlockingKernelClient, code: str, subshell_id: str | None
4952
def execute_request_subshell_id(
5053
kc: BlockingKernelClient, code: str, subshell_id: str | None, terminator: str = "\n"
5154
):
52-
msg = execute_request(kc, code, subshell_id)
53-
msg_id = msg["msg_id"]
54-
stdout = ""
55-
while True:
56-
msg = kc.get_iopub_msg()
57-
# Get the stream messages corresponding to msg_id
58-
if (
59-
msg["msg_type"] == "stream"
60-
and msg["parent_header"]["msg_id"] == msg_id
61-
and msg["content"]["name"] == "stdout"
62-
):
63-
stdout += msg["content"]["text"]
64-
if stdout.endswith(terminator):
65-
break
55+
execute_request(kc, code, subshell_id)
56+
stdout, _ = assemble_output(kc.get_iopub_msg)
6657
return stdout.strip()
6758

6859

0 commit comments

Comments
 (0)