matplotlib/matplotlib — pull request #1905 by jschueller (2013-04-15 07:28:59+00:00)
Title: Prevent Qt4 from stopping the interpreter

Hi,

This commit prevents Qt4 from stopping the interpreter:
If there's no X server available, or if you export DISPLAY="", and try to initialize a QApp, Qt4 stops:
: cannot connect to X server

It's a non-feature of Qt4 to not use exceptions to be lightweight.
But in python, that's not really the spirit, we'd expect a python backtrace, so here's what the patch does:
Traceback (most recent call last):
File "", line 1, in
File "/home/schueller/projects/matplotlib/install/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/pyplot.py", line 348, in figure
**kwargs)
...
raise RuntimeError( 'Qt4 failed to initialize ' + p.stderr.readline().rstrip() )
RuntimeError: Qt4 failed to initialize : cannot connect to X server

And it's more like the other backends do:
_tkinter.TclError: couldn't connect to display ""

Regards.