PyQt5 Class Properties Go Missing When Using QThreadPool



  • I'm getting the strangest errors with PyQt5. I'm wondering if anyone else has had this problem. If I'm running running threads using the QThreadPool and QRunnable objects, sometimes my Python classes lose their properties. Here's some example code:

    RunnableSignals.py
    @
    from PyQt5.QtCore import *

    class RunnableSignals(QObject):
    finished = pyqtSignal(dict)

    def init(self):
    super(RunnableSignals, self).init()

    class Runnable(QRunnable):
    def init(self, inputData):
    super(Runnable, self).init()

    self._inputData = inputData
    self.abort = False
    self.signals = RunnableSignals()

    def aborted(self):
    return self.abort

    def run(self):
    if self.aborted():
    return

    Do stuff. Check if aborted along the way

    self.signals.finished.emit(data)
    @

    In a different class in the main thread:
    @
    def update(self):
    self.runnable = Runnable(someVariable)
    self.runnable.signals.finished.connect(self.onFinished)
    QThreadPool.globalInstance().start(self.runnable)
    @

    If I run two at a time, the first one is just fine, but the second one will raise an error. AttributeError: 'Runnable' object has no attribute 'abort'. It just makes no sense, I set self.abort = False in the init method.
    Also, I don't know if this is worth mentioning, but I'm using Python.NET instead of C Python. Don't know if that has something to do with it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.