From 3a42b33124d6036dacee85867e484cb25d32a903 2016-07-21 12:36:33 From: Thomas Kluyver Date: 2016-07-21 12:36:33 Subject: [PATCH] Create a QApplication for inputhook if one doesn't already exist Closes gh-9784 --- diff --git a/IPython/terminal/pt_inputhooks/qt.py b/IPython/terminal/pt_inputhooks/qt.py index ebf3a94..34c9618 100644 --- a/IPython/terminal/pt_inputhooks/qt.py +++ b/IPython/terminal/pt_inputhooks/qt.py @@ -1,10 +1,15 @@ import sys from IPython.external.qt_for_kernel import QtCore, QtGui +# If we create a QApplication, keep a reference to it so that it doesn't get +# garbage collected. +_appref = None + def inputhook(context): + global _appref app = QtCore.QCoreApplication.instance() if not app: - return + _appref = app = QtGui.QApplication([" "]) event_loop = QtCore.QEventLoop(app) if sys.platform == 'win32':