Skip to content

Commit 10612cd

Browse files
committed
use poll method to fix the test
1 parent 22f5135 commit 10612cd

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

ipykernel/eventloops.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,21 @@ def process_stream_events(shell_stream):
451451

452452
shell_stream = get_shell_stream(kernel)
453453
notifier = partial(process_stream_events, shell_stream)
454-
loop.add_reader(shell_stream.getsockopt(zmq.FD), notifier)
455-
loop.call_soon(notifier)
454+
455+
if os.name=='nt':
456+
stop_event=asyncio.Event()
457+
def blocking_poll():
458+
poller=zmq.Poller()
459+
poller.register(shell_stream.socket, zmq.POLLIN)
460+
461+
while stop_event.is_set():
462+
events=poller.poll(None)
463+
if events:
464+
loop.calls_soon_threadsafe(notifier)
465+
t = threading.Thread(target=blocking_poll, daemon=True).start()
466+
else:
467+
loop.add_reader(shell_stream.getsockopt(zmq.FD), notifier)
468+
loop.call_soon(notifier)
456469

457470
while True:
458471
error = None
@@ -463,6 +476,9 @@ def process_stream_events(shell_stream):
463476
except Exception as e:
464477
error = e
465478
if loop._should_close: # type:ignore[attr-defined]
479+
if os.name=='nt':
480+
stop_event.set()
481+
t.join()
466482
loop.close()
467483
if error is not None:
468484
raise error

0 commit comments

Comments
 (0)