Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5c222df

Browse files
author
Julien Schueller
committed
Prevented Qt4 from stopping the interpreter.
1 parent 1ccf29d commit 5c222df

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/matplotlib/backends/backend_qt4.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
from qt4_compat import QtCore, QtGui, _getSaveFileName, __version__
2525

26+
import subprocess
27+
2628
backend_version = __version__
2729
def fn_name(): return sys._getframe(1).f_code.co_name
2830

@@ -53,6 +55,15 @@ def _create_qApp():
5355
global qApp
5456
app = QtGui.QApplication.instance()
5557
if app is None:
58+
59+
# try to launch a QApplication in a separate process
60+
# otherwise it may stop the intepreter on failure (if no X server for example)
61+
p = subprocess.Popen(sys.executable, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
62+
p.stdin.write('from matplotlib.backends.qt4_compat import QtGui\napp = QtGui.QApplication([])\n')
63+
p.stdin.close()
64+
if p.wait() != 0:
65+
raise RuntimeError( 'Qt4 failed to initialize ' + p.stderr.readline().rstrip() )
66+
5667
qApp = QtGui.QApplication( [" "] )
5768
QtCore.QObject.connect( qApp, QtCore.SIGNAL( "lastWindowClosed()" ),
5869
qApp, QtCore.SLOT( "quit()" ) )

0 commit comments

Comments
 (0)