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

List:       pykde
Subject:    Re: [PyQt] Exception propagation in the exec_() loop
From:       "Bryan A. Jones" <bjones () ece ! msstate ! edu>
Date:       2014-01-24 16:10:44
Message-ID: CAHhYbD9t8OtNt=ZMXhCRtnG3xq4vfRUoC196FDk5bKyHGnaGCw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Yuya,

Thanks -- that was exactly what I needed! The revised, working code:

import sys
from PyQt4.QtCore import QTimer
from PyQt4.QtGui import QApplication

def af():
    assert False

def main():
    sys.excepthook = lambda type, value, traceback: app.quit()
    app = QApplication(sys.argv)
    QTimer.singleShot(0, af)
    app.exec_()

if __name__ == '__main__':
    main()


Bryan


On Fri, Jan 24, 2014 at 5:25 AM, Yuya Nishihara <yuya@tcha.org> wrote:

> On Thu, 23 Jan 2014 13:43:32 -0600, Bryan A. Jones wrote:
> > It seems that exceptions which occur in an event loop (when calling
> > app.exec_(), for instance) are caught and printed, but not passed on. Is
> > there any way to allow exceptions to propagate past exec_()? As a
> concrete
> > example, the following code prints the following backtrace, but doesn't
> > exit.
> >
> > import sys
> > from PyQt4.QtCore import QTimer
> > from PyQt4.QtGui import QApplication
> >
> > def af():
> >     assert False
> >
> > def main():
> >     app = QApplication(sys.argv)
> >     QTimer.singleShot(0, af)
> >     app.exec_()
>
> You can install sys.excepthook for uncaught exceptions.
>
> http://docs.python.org/2.7/library/sys.html#sys.excepthook
>
> Regards,
>



-- 
Bryan A. Jones, Ph.D.
Associate Professor
Department of Electrical and Computer Engineering
231 Simrall / PO Box 9571
Mississippi State University
Mississippi state, MS 39762
http://www.ece.msstate.edu/~bjones
bjones AT ece DOT msstate DOT edu
voice 662-325-3149
fax 662-325-2298

Our Master, Jesus Christ, is on his way. He'll show up right on
time, his arrival guaranteed by the Blessed and Undisputed Ruler,
High King, High God.
- 1 Tim. 6:14b-15 (The Message)

[Attachment #5 (text/html)]

<div dir="ltr">Yuya,<div><br></div><div>Thanks -- that was exactly what I needed! The \
revised, working code:</div><div><br></div><div><div>import sys</div><div>from \
PyQt4.QtCore import QTimer</div><div>from PyQt4.QtGui import QApplication</div>

<div><br></div><div>def af():</div><div>    assert False</div><div>    </div><div>def \
main():       </div><div>    sys.excepthook = lambda type, value, traceback: \
app.quit()</div><div>    app = QApplication(sys.argv)</div>

<div>    QTimer.singleShot(0, af)</div><div>    \
app.exec_()</div><div><br></div><div>if __name__ == &#39;__main__&#39;:</div><div>    \
main()</div></div><div><br></div><div><br></div><div>Bryan</div></div><div \
class="gmail_extra">

<br><br><div class="gmail_quote">On Fri, Jan 24, 2014 at 5:25 AM, Yuya Nishihara \
<span dir="ltr">&lt;<a href="mailto:yuya@tcha.org" \
target="_blank">yuya@tcha.org</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">

<div class="im">On Thu, 23 Jan 2014 13:43:32 -0600, Bryan A. Jones wrote:<br>
&gt; It seems that exceptions which occur in an event loop (when calling<br>
&gt; app.exec_(), for instance) are caught and printed, but not passed on. Is<br>
&gt; there any way to allow exceptions to propagate past exec_()? As a concrete<br>
&gt; example, the following code prints the following backtrace, but doesn&#39;t<br>
&gt; exit.<br>
&gt;<br>
&gt; import sys<br>
&gt; from PyQt4.QtCore import QTimer<br>
&gt; from PyQt4.QtGui import QApplication<br>
&gt;<br>
&gt; def af():<br>
&gt;     assert False<br>
&gt;<br>
&gt; def main():<br>
&gt;     app = QApplication(sys.argv)<br>
&gt;     QTimer.singleShot(0, af)<br>
&gt;     app.exec_()<br>
<br>
</div>You can install sys.excepthook for uncaught exceptions.<br>
<br>
<a href="http://docs.python.org/2.7/library/sys.html#sys.excepthook" \
target="_blank">http://docs.python.org/2.7/library/sys.html#sys.excepthook</a><br> \
<br> Regards,<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Bryan A. Jones, \
Ph.D.<br>Associate Professor<br>Department of Electrical and Computer \
Engineering<br>231 Simrall / PO Box 9571<br>Mississippi State University<br>

Mississippi state, MS 39762<br><a href="http://www.ece.msstate.edu/~bjones" \
target="_blank">http://www.ece.msstate.edu/~bjones</a><br>bjones AT ece DOT msstate \
DOT edu<br>voice 662-325-3149<br>fax 662-325-2298<br><br>Our Master, Jesus Christ, is \
on his way. He&#39;ll show up right on<br>

time, his arrival guaranteed by the Blessed and Undisputed Ruler,<br>High King, High \
God.<br>- 1 Tim. 6:14b-15 (The Message)<br> </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