Skip to content

Commit

Permalink
consistent shadow socket creation
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Oct 22, 2024
1 parent 9ae6940 commit b1d0ed5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ipykernel/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async def _handle_event(self):
*all* waiting events are processed in order.
"""
# create async wrapper within coroutine
pipe_in = zmq.asyncio.Socket.shadow(self._pipe_in0)
pipe_in = zmq.asyncio.Socket(self._pipe_in0)
try:
while True:
await pipe_in.recv()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import zmq.asyncio
from jupyter_client.session import Session

from ipykernel.iostream import MASTER, BackgroundSocket, IOPubThread, OutStream
from ipykernel.iostream import _MAIN, BackgroundSocket, IOPubThread, OutStream


@pytest.fixture()
Expand Down Expand Up @@ -73,7 +73,7 @@ async def test_io_thread(anyio_backend, iopub_thread):
ctx1, pipe = thread._setup_pipe_out()
pipe.close()
thread._pipe_in1.close()
thread._check_mp_mode = lambda: MASTER
thread._check_mp_mode = lambda: _MAIN
thread._really_send([b"hi"])
ctx1.destroy()
thread.stop()
Expand Down
24 changes: 12 additions & 12 deletions tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
)


def _check_master(kc, expected=True, stream="stdout"):
def _check_main(kc, expected=True, stream="stdout"):
execute(kc=kc, code="import sys")
flush_channels(kc)
msg_id, content = execute(kc=kc, code="print(sys.%s._is_master_process())" % stream)
msg_id, content = execute(kc=kc, code="print(sys.%s._is_main_process())" % stream)
stdout, stderr = assemble_output(kc.get_iopub_msg)
assert stdout.strip() == repr(expected)

Expand All @@ -56,7 +56,7 @@ def test_simple_print():
stdout, stderr = assemble_output(kc.get_iopub_msg)
assert stdout == "hi\n"
assert stderr == ""
_check_master(kc, expected=True)
_check_main(kc, expected=True)


def test_print_to_correct_cell_from_thread():
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_capture_fd():
stdout, stderr = assemble_output(iopub)
assert stdout == "capsys\n"
assert stderr == ""
_check_master(kc, expected=True)
_check_main(kc, expected=True)


@pytest.mark.skip(reason="Currently don't capture during test as pytest does its own capturing")
Expand All @@ -182,7 +182,7 @@ def test_subprocess_peek_at_stream_fileno():
stdout, stderr = assemble_output(iopub)
assert stdout == "CAP1\nCAP2\n"
assert stderr == ""
_check_master(kc, expected=True)
_check_main(kc, expected=True)


def test_sys_path():
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_sys_path_profile_dir():
def test_subprocess_print():
"""printing from forked mp.Process"""
with new_kernel() as kc:
_check_master(kc, expected=True)
_check_main(kc, expected=True)
flush_channels(kc)
np = 5
code = "\n".join(
Expand All @@ -238,8 +238,8 @@ def test_subprocess_print():
for n in range(np):
assert stdout.count(str(n)) == 1, stdout
assert stderr == ""
_check_master(kc, expected=True)
_check_master(kc, expected=True, stream="stderr")
_check_main(kc, expected=True)
_check_main(kc, expected=True, stream="stderr")


@flaky(max_runs=3)
Expand All @@ -261,8 +261,8 @@ def test_subprocess_noprint():
assert stdout == ""
assert stderr == ""

_check_master(kc, expected=True)
_check_master(kc, expected=True, stream="stderr")
_check_main(kc, expected=True)
_check_main(kc, expected=True, stream="stderr")


@flaky(max_runs=3)
Expand All @@ -287,8 +287,8 @@ def test_subprocess_error():
assert stdout == ""
assert "ValueError" in stderr

_check_master(kc, expected=True)
_check_master(kc, expected=True, stream="stderr")
_check_main(kc, expected=True)
_check_main(kc, expected=True, stream="stderr")


# raw_input tests
Expand Down

0 comments on commit b1d0ed5

Please sign in to comment.