[PyQt] PyQt can halt the interpreter on an X11 build of Qt

Julien Schueller julien.schueller at gmail.com
Fri Apr 19 09:14:26 BST 2013


Hi,

With a X11 build of Qt, if there's no X server available, or the DISPLAY
env var is invalid, (ssh batch mode, ...)
then Qt exits (like in exit(1); ), with the message
: cannot connect to X server

That's a non-feature of Qt to not raise exceptions, in order to be
lighweight or more compatible,
but in the python side we'd expect a traceback, and that could be
considered as a bug.

You can reproduce it simply:
DISPLAY="" python -c "from PyQt4 import QtGui; app =
QtGui.QApplication([]); print 'Not executed' "

A workaround is to trying to check if on an X11 build, and trying to assess
the validity of DISPLAY env var with:
if hasattr(QtGui, 'QX11Info'):
    display = os.environ.get('DISPLAY')
    if display is None or not re.search(':\d', display):
        raise RuntimeError('Invalid DISPLAY variable')
But I think it'd be great if it could be raised within pyqt.


-- 
J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130419/979294fa/attachment.html>


More information about the PyQt mailing list