File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -431,6 +431,7 @@ def loop_cocoa_exit(kernel):
431431def loop_asyncio (kernel ):
432432 """Start a kernel with asyncio event loop support."""
433433 import asyncio
434+ import threading
434435
435436 loop = asyncio .get_event_loop ()
436437 # loop is already running (e.g. tornado 5), nothing left to do
@@ -452,19 +453,21 @@ def process_stream_events(shell_stream):
452453 shell_stream = get_shell_stream (kernel )
453454 notifier = partial (process_stream_events , shell_stream )
454455
455- if os .name == "nt" :
456+ if os .name == 'nt' :
456457 stop_event = asyncio .Event ()
458+ t = None
457459
458460 def blocking_poll ():
459461 poller = zmq .Poller ()
460462 poller .register (shell_stream .socket , zmq .POLLIN )
461463
462- while stop_event .is_set ():
464+ while not stop_event .is_set ():
463465 events = poller .poll (None )
464466 if events :
465- loop .calls_soon_threadsafe (notifier )
466-
467- t = threading .Thread (target = blocking_poll , daemon = True ).start ()
467+ loop .call_soon_threadsafe (notifier )
468+
469+ t = threading .Thread (target = blocking_poll , daemon = True )
470+ t .start ()
468471 else :
469472 loop .add_reader (shell_stream .getsockopt (zmq .FD ), notifier )
470473 loop .call_soon (notifier )
@@ -478,9 +481,10 @@ def blocking_poll():
478481 except Exception as e :
479482 error = e
480483 if loop ._should_close : # type:ignore[attr-defined]
481- if os .name == "nt" :
484+ if os .name == 'nt' :
482485 stop_event .set ()
483- t .join ()
486+ if t is not None :
487+ t .join ()
484488 loop .close ()
485489 if error is not None :
486490 raise error
You can’t perform that action at this time.
0 commit comments