From 07bdb406dbdf2333fd2ab060725dceb83452e6ac 2017-02-21 17:12:13 From: Matthias Bussonnier <bussonniermatthias@gmail.com> Date: 2017-02-21 17:12:13 Subject: [PATCH] Merge pull request #10311 from ipython/auto-backport-of-pr-10301 Backport PR #10301 on branch 5.x --- diff --git a/IPython/terminal/pt_inputhooks/qt.py b/IPython/terminal/pt_inputhooks/qt.py index 34c9618..0de9c3d 100644 --- a/IPython/terminal/pt_inputhooks/qt.py +++ b/IPython/terminal/pt_inputhooks/qt.py @@ -5,6 +5,7 @@ from IPython.external.qt_for_kernel import QtCore, QtGui # garbage collected. _appref = None + def inputhook(context): global _appref app = QtCore.QCoreApplication.instance() @@ -24,7 +25,11 @@ def inputhook(context): 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 = QtCore.QSocketNotifier(context.fileno(), + QtCore.QSocketNotifier.Read) + # connect the callback we care about before we turn it on notifier.activated.connect(event_loop.exit) - event_loop.exec_() + notifier.setEnabled(True) + # only start the event loop we are not already flipped + if not context.input_is_ready(): + event_loop.exec_()