Skip to content

Commit 40af2b0

Browse files
committed
Debug
1 parent 0926542 commit 40af2b0

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

tests/test_subshells.py

Lines changed: 18 additions & 6 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, assemble_output, get_replies, get_reply, new_kernel
13+
from .utils import TIMEOUT, get_replies, get_reply, new_kernel, wait_for_idle
1414

1515
# Helpers
1616

@@ -20,7 +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, None) # wait for idle
23+
wait_for_idle(kc)
2424
return reply["content"]
2525

2626

@@ -29,7 +29,7 @@ def delete_subshell_helper(kc: BlockingKernelClient, subshell_id: str):
2929
kc.control_channel.send(msg)
3030
msg_id = msg["header"]["msg_id"]
3131
reply = get_reply(kc, msg_id, TIMEOUT, channel="control")
32-
assemble_output(kc.get_iopub_msg, None) # wait for idle
32+
wait_for_idle(kc)
3333
return reply["content"]
3434

3535

@@ -38,7 +38,7 @@ def list_subshell_helper(kc: BlockingKernelClient):
3838
kc.control_channel.send(msg)
3939
msg_id = msg["header"]["msg_id"]
4040
reply = get_reply(kc, msg_id, TIMEOUT, channel="control")
41-
assemble_output(kc.get_iopub_msg, None) # wait for idle
41+
wait_for_idle(kc)
4242
return reply["content"]
4343

4444

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

5971

0 commit comments

Comments
 (0)