[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] PyQt can halt the interpreter on an X11 build of Qt
From:       Julien Schueller <julien.schueller () gmail ! com>
Date:       2013-04-19 8:14:26
Message-ID: CANV9NRN69SXkvhdygz2LrNCE7sONTGosdG7ZjNp4xhmNiVOp8A () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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

[Attachment #5 (text/html)]

<div dir="ltr"><div><div><div>Hi,<br><br></div>With a X11 build of Qt, if there&#39;s \
no X server available, or the DISPLAY env var is invalid, (ssh batch mode, \
...)<br></div>then Qt exits (like in exit(1); ), with the message<br> : cannot \
connect to X server <br><br></div>That&#39;s a non-feature of Qt to not raise \
exceptions, in order to be lighweight or more compatible,<br>but in the python side \
we&#39;d expect a traceback, and that could be considered as a bug.<br> \
<div><div><div><div><br>You can reproduce it simply:<br>DISPLAY=&quot;&quot; python \
-c &quot;from PyQt4 import QtGui; app = QtGui.QApplication([]); print &#39;Not \
executed&#39; &quot;<br></div><div></div><div><br></div><div> A workaround is to \
trying to check if on an X11 build, and trying to assess the validity of DISPLAY env \
var with:<br>if hasattr(QtGui, &#39;QX11Info&#39;):<br>       display = \
os.environ.get(&#39;DISPLAY&#39;)<br>       if display is None or not \
re.search(&#39;:\d&#39;, display): <br>  raise RuntimeError(&#39;Invalid DISPLAY \
variable&#39;)               <br></div><div>But I think it&#39;d be great if it could \
be raised within pyqt.<br></div><div><br clear="all"></div><div><div><br>-- \
<br>J</div></div></div> </div></div></div>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic