Skip to content

Commit 19d61d0

Browse files
committed
-
1 parent ed2552d commit 19d61d0

File tree

3 files changed

+29
-52
lines changed

3 files changed

+29
-52
lines changed

Diff for: ipykernel/kernelapp.py

-31
Original file line numberDiff line numberDiff line change
@@ -635,36 +635,6 @@ def configure_tornado_logger(self):
635635
handler.setFormatter(formatter)
636636
logger.addHandler(handler)
637637

638-
def _init_asyncio_patch(self):
639-
"""set default asyncio policy to be compatible with tornado
640-
Tornado 6 (at least) is not compatible with the default
641-
asyncio implementation on Windows
642-
Pick the older SelectorEventLoopPolicy on Windows
643-
if the known-incompatible default policy is in use.
644-
Support for Proactor via a background thread is available in tornado 6.1,
645-
but it is still preferable to run the Selector in the main thread
646-
instead of the background.
647-
do this as early as possible to make it a low priority and overridable
648-
ref: https://github.com/tornadoweb/tornado/issues/2608
649-
FIXME: if/when tornado supports the defaults in asyncio without threads,
650-
remove and bump tornado requirement for py38.
651-
Most likely, this will mean a new Python version
652-
where asyncio.ProactorEventLoop supports add_reader and friends.
653-
"""
654-
if sys.platform.startswith("win"):
655-
import asyncio
656-
657-
try:
658-
from asyncio import WindowsProactorEventLoopPolicy, WindowsSelectorEventLoopPolicy
659-
except ImportError:
660-
pass
661-
# not affected
662-
else:
663-
if type(asyncio.get_event_loop_policy()) is WindowsProactorEventLoopPolicy:
664-
# WindowsProactorEventLoopPolicy is not compatible with tornado 6
665-
# fallback to the pre-3.8 default of Selector
666-
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
667-
668638
def init_pdb(self):
669639
"""Replace pdb with IPython's version that is interruptible.
670640
@@ -684,7 +654,6 @@ def init_pdb(self):
684654
@catch_config_error
685655
def initialize(self, argv=None):
686656
"""Initialize the application."""
687-
self._init_asyncio_patch()
688657
super().initialize(argv)
689658
if self.subapp is not None:
690659
return

Diff for: tests/conftest.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import logging
32
import os
43
from math import inf
@@ -42,11 +41,6 @@
4241
resource.setrlimit(resource.RLIMIT_NOFILE, (soft, hard))
4342

4443

45-
# Enforce selector event loop on Windows.
46-
if os.name == "nt":
47-
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type:ignore
48-
49-
5044
class TestSession(Session):
5145
"""A session that copies sent messages to an internal stream, so that
5246
they can be accessed later.

Diff for: tests/test_async.py

+29-15
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,44 @@
44
import time
55

66
import pytest
7+
import zmq
8+
from zmq_anyio import Socket
79

810
from .test_message_spec import validate_message
911
from .utils import TIMEOUT, execute, flush_channels, start_new_kernel
1012

1113
KC = KM = None
1214

1315

14-
@pytest.fixture(autouse=True)
15-
def _setup_env():
16-
"""start the global kernel (if it isn't running) and return its client"""
17-
global KM, KC
18-
KM, KC = start_new_kernel()
19-
flush_channels(KC)
20-
yield
21-
assert KC is not None
22-
assert KM is not None
23-
KC.stop_channels()
24-
KM.shutdown_kernel(now=True)
16+
async def test_context():
17+
context = zmq.Context()
18+
a, b = Socket(context, zmq.PAIR), Socket(context, zmq.PAIR)
19+
port = a.bind_to_random_port("tcp://127.0.0.1")
20+
b.connect(f"tcp://127.0.0.1:{port}")
21+
a.send(b"Hello")
22+
assert b.recv() == b"Hello"
23+
async with a, b:
24+
await a.asend(b"Hello")
25+
assert await b.arecv() == b"Hello"
2526

2627

27-
def test_async_await():
28-
flush_channels(KC)
29-
msg_id, content = execute("import asyncio; await asyncio.sleep(0.1)", KC)
30-
assert content["status"] == "ok", content
28+
# @pytest.fixture(autouse=True)
29+
# def _setup_env():
30+
# """start the global kernel (if it isn't running) and return its client"""
31+
# global KM, KC
32+
# KM, KC = start_new_kernel()
33+
# flush_channels(KC)
34+
# yield
35+
# assert KC is not None
36+
# assert KM is not None
37+
# KC.stop_channels()
38+
# KM.shutdown_kernel(now=True)
39+
#
40+
#
41+
# def test_async_await():
42+
# flush_channels(KC)
43+
# msg_id, content = execute("import asyncio; await asyncio.sleep(0.1)", KC)
44+
# assert content["status"] == "ok", content
3145

3246

3347
@pytest.mark.skipif(os.name == "nt", reason="Cannot interrupt on Windows")

0 commit comments

Comments
 (0)