From e9301c9b52a1ebd4f72527098da896097f46c5fa 2016-07-06 10:20:00 From: Thomas Kluyver Date: 2016-07-06 10:20:00 Subject: [PATCH] Try to fix Qt event loop, take III This involves neither threads nor calling in to the old inputhook machinery. --- diff --git a/IPython/terminal/pt_inputhooks/qt.py b/IPython/terminal/pt_inputhooks/qt.py index 1fd4e92..ebf3a94 100644 --- a/IPython/terminal/pt_inputhooks/qt.py +++ b/IPython/terminal/pt_inputhooks/qt.py @@ -1,3 +1,4 @@ +import sys from IPython.external.qt_for_kernel import QtCore, QtGui def inputhook(context): @@ -5,7 +6,20 @@ def inputhook(context): if not app: return event_loop = QtCore.QEventLoop(app) - notifier = QtCore.QSocketNotifier(context.fileno(), QtCore.QSocketNotifier.Read) - notifier.setEnabled(True) - notifier.activated.connect(event_loop.exit) - event_loop.exec_() + + if sys.platform == 'win32': + # The QSocketNotifier method doesn't appear to work on Windows. + # Use polling instead. + timer = QtCore.QTimer() + timer.timeout.connect(event_loop.quit) + while not context.input_is_ready(): + timer.start(50) # 50 ms + event_loop.exec_() + timer.stop() + else: + # On POSIX platforms, we can use a file descriptor to quit the event + # loop when there is input ready to read. + notifier = QtCore.QSocketNotifier(context.fileno(), QtCore.QSocketNotifier.Read) + notifier.setEnabled(True) + notifier.activated.connect(event_loop.exit) + event_loop.exec_()