[PyQt] [BUG] No exception reports in a QThread with Python 3

Richie Ward richies at gmail.com
Sun Feb 3 14:55:51 GMT 2013


If you run the following code with Python 3, you will not recieve a
exception; dispite it being blatently wrong.
import sys
from PyQt4 import QtGui, QtCore

class FooThread(QtCore.QThread):

    def run(self):
        beeswax
        return


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)

    ft = FooThread()
    ft.start()
    sys.exit(app.exec_())



Avaris on #pyqt @ freenode managed to come up with this workaround:

import sys
import time
import traceback
from PyQt4 import QtGui, QtCore

def excepthook(exc_type, exc_val, tracebackobj):
    message = ''.join(traceback.format_exception(exc_type, exc_val,
tracebackobj))

    print('EXCEPTHOOK')
    print(message)
    print('*'*30)

sys.excepthook = excepthook

class FooThread(QtCore.QThread):
    def run(self):
        time.sleep(1)
        beeswaxThread

class FooObject(QtCore.QObject):
    finished = QtCore.pyqtSignal()

    def run(self):
        time.sleep(2)
        beeswaxObject
        self.finished.emit()

if __name__ == "__main__":
    app = QtCore.QCoreApplication(sys.argv)

    thread = QtCore.QThread()
    fooObject = FooObject()
    fooObject.moveToThread(thread)
    thread.started.connect(fooObject.run)
    fooObject.finished.connect(thread.quit)

    fooThread = FooThread()

    thread.start()
    fooThread.start()

    QtCore.QTimer.singleShot(3000, app.quit)
    sys.exit(app.exec_())

My test system that I use to reproduce this is:
PyQt 4.9.6 - Built from source.
Ubuntu 12.10
Pythion 3.2

The guys on IRC confirmed this was a bug for me too.

-- 
Thanks, Richie Ward


More information about the PyQt mailing list