[PyQt] Exception propagation in the exec_() loop
Bryan A. Jones
bjones at ece.msstate.edu
Fri Jan 24 16:10:44 GMT 2014
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 at 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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140124/af334d61/attachment.html>
More information about the PyQt
mailing list