Hello,
I apologize if this is the wrong place to post this. I don’t know where the problem is coming from and I’ve tried posting on the Qt forums, but still no answer.
I’m using QThreadPool and QRunnable to keep the user interface responsive, but I keep running into errors that happen inconsistently. I’ll post some example code to make things clearer.
Runnable.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)
Test.py
class Test(QObject):
def __init__(self):
super(Test, self).__init__()
def update(self):
self.runnable = Runnable(someVariable)
self.runnable.signals.finished.connect(self.onFinished)
QThreadPool.globalInstance().start(self.runnable)
I keep getting the error AttributeError: ‘Runnable’ object has no attribute ‘abort’. How is this possible if it was declared in the constructor before the thread is even run? Also, it doesn’t error 100% of the time. Sometimes it works.
I don’t know if this has something to do with Qt, or if it’s PyQt, or if it’s Python .NET to blame.