@@ -21,7 +21,7 @@ def _use_appnope():
2121 return sys .platform == "darwin" and V (platform .mac_ver ()[0 ]) >= V ("10.9" )
2222
2323
24- def _notify_stream_qt (kernel , stream ):
24+ def _notify_stream_qt (kernel ):
2525
2626 from IPython .external .qt_for_kernel import QtCore
2727
@@ -31,24 +31,29 @@ def process_stream_events():
3131 # due to our consuming of the edge-triggered FD
3232 # flush returns the number of events consumed.
3333 # if there were any, wake it up
34- if stream .flush (limit = 1 ):
35- notifier .setEnabled (False )
34+ if kernel . shell_stream .flush (limit = 1 ):
35+ kernel . _qt_notifier .setEnabled (False )
3636 kernel .app .quit ()
3737
38- fd = stream .getsockopt (zmq .FD )
39- notifier = QtCore .QSocketNotifier (fd , QtCore .QSocketNotifier .Read , kernel .app )
40- notifier .activated .connect (process_stream_events )
38+ if not hasattr (kernel , "_qt_notifier" ):
39+ fd = kernel .shell_stream .getsockopt (zmq .FD )
40+ kernel ._qt_notifier = QtCore .QSocketNotifier (fd , QtCore .QSocketNotifier .Read , kernel .app )
41+ kernel ._qt_notifier .activated .connect (process_stream_events )
42+ else :
43+ kernel ._qt_notifier .setEnabled (True )
44+
4145 # there may already be unprocessed events waiting.
4246 # these events will not wake zmq's edge-triggered FD
4347 # since edge-triggered notification only occurs on new i/o activity.
4448 # process all the waiting events immediately
4549 # so we start in a clean state ensuring that any new i/o events will notify.
4650 # schedule first call on the eventloop as soon as it's running,
4751 # so we don't block here processing events
48- timer = QtCore .QTimer (kernel .app )
49- timer .setSingleShot (True )
50- timer .timeout .connect (process_stream_events )
51- timer .start (0 )
52+ if not hasattr (kernel , "_qt_timer" ):
53+ kernel ._qt_timer = QtCore .QTimer (kernel .app )
54+ kernel ._qt_timer .setSingleShot (True )
55+ kernel ._qt_timer .timeout .connect (process_stream_events )
56+ kernel ._qt_timer .start (0 )
5257
5358
5459# mapping of keys to loop functions
@@ -118,7 +123,7 @@ def loop_qt4(kernel):
118123 kernel .app = get_app_qt4 ([" " ])
119124 if isinstance (kernel .app , QtGui .QApplication ):
120125 kernel .app .setQuitOnLastWindowClosed (False )
121- _notify_stream_qt (kernel , kernel . shell_stream )
126+ _notify_stream_qt (kernel )
122127
123128 _loop_qt (kernel .app )
124129
0 commit comments