@@ -93,11 +93,11 @@ def process_stream_events():
93
93
# due to our consuming of the edge-triggered FD
94
94
# flush returns the number of events consumed.
95
95
# if there were any, wake it up
96
- if kernel .shell_stream . flush ( limit = 1 ) :
96
+ if ( kernel .shell_socket . get ( zmq . EVENTS ) & zmq . POLLIN ) > 0 :
97
97
exit_loop ()
98
98
99
99
if not hasattr (kernel , "_qt_notifier" ):
100
- fd = kernel .shell_stream .getsockopt (zmq .FD )
100
+ fd = kernel .shell_socket .getsockopt (zmq .FD )
101
101
kernel ._qt_notifier = QtCore .QSocketNotifier (
102
102
fd , enum_helper ("QtCore.QSocketNotifier.Type" ).Read , kernel .app .qt_event_loop
103
103
)
@@ -179,7 +179,7 @@ def loop_wx(kernel):
179
179
180
180
def wake ():
181
181
"""wake from wx"""
182
- if kernel .shell_stream . flush ( limit = 1 ) :
182
+ if ( kernel .shell_socket . get ( zmq . EVENTS ) & zmq . POLLIN ) > 0 :
183
183
kernel .app .ExitMainLoop ()
184
184
return
185
185
@@ -248,14 +248,14 @@ def __init__(self, app):
248
248
249
249
def exit_loop ():
250
250
"""fall back to main loop"""
251
- app .tk .deletefilehandler (kernel .shell_stream .getsockopt (zmq .FD ))
251
+ app .tk .deletefilehandler (kernel .shell_socket .getsockopt (zmq .FD ))
252
252
app .quit ()
253
253
app .destroy ()
254
254
del kernel .app_wrapper
255
255
256
256
def process_stream_events (* a , ** kw ):
257
257
"""fall back to main loop when there's a socket event"""
258
- if kernel .shell_stream . flush ( limit = 1 ) :
258
+ if ( kernel .shell_socket . get ( zmq . EVENTS ) & zmq . POLLIN ) > 0 :
259
259
exit_loop ()
260
260
261
261
# allow for scheduling exits from the loop in case a timeout needs to
@@ -269,7 +269,7 @@ def _schedule_exit(delay):
269
269
# For Tkinter, we create a Tk object and call its withdraw method.
270
270
kernel .app_wrapper = BasicAppWrapper (app )
271
271
app .tk .createfilehandler (
272
- kernel .shell_stream .getsockopt (zmq .FD ), READABLE , process_stream_events
272
+ kernel .shell_socket .getsockopt (zmq .FD ), READABLE , process_stream_events
273
273
)
274
274
# schedule initial call after start
275
275
app .after (0 , process_stream_events )
@@ -377,7 +377,7 @@ def handle_int(etype, value, tb):
377
377
# don't let interrupts during mainloop invoke crash_handler:
378
378
sys .excepthook = handle_int
379
379
mainloop (kernel ._poll_interval )
380
- if kernel .shell_stream . flush ( limit = 1 ) :
380
+ if ( kernel .shell_socket . get ( zmq . EVENTS ) & zmq . POLLIN ) > 0 :
381
381
# events to process, return control to kernel
382
382
return
383
383
except BaseException :
@@ -604,3 +604,11 @@ def enable_gui(gui, kernel=None):
604
604
kernel .eventloop = loop
605
605
# We set `eventloop`; the function the user chose is executed in `Kernel.enter_eventloop`, thus
606
606
# any exceptions raised during the event loop will not be shown in the client.
607
+
608
+ # If running in async loop then set anyio event to trigger starting the eventloop.
609
+ # If not running in async loop do nothing as this will be handled in IPKernelApp.main().
610
+ try :
611
+ kernel ._eventloop_set .set ()
612
+ except RuntimeError :
613
+ # Expecting sniffio.AsyncLibraryNotFoundError but don't want to import sniffio just for that
614
+ pass
0 commit comments