I have a multi-threaded application written in Python in which one thread \"takes care\" of the GUI, and the other is the worker thread. However, the worker thread has two m
Eli Bendersky's answer is correct, however the order of arguments appears wrong.
If you call the Worker class like this:
The argument order that worked for me:
def __init__(self, parent=None, do_create_data=True):
The order shown in Eli Bendersky's answer produced this error message for me:
TypeError: QThread(QObject parent=None): argument 1 has unexpected type 'str'
Not sure why, but I'm sure someone can help explain.
The start
method of QThread
doesn't accept arguments. However, you've inherited QThread
so you're free to customize it at will. So, to implement what you want, just pass arguments into the constructor of Worker
.
Here's your code sample slightly modified to show this in action:
class Worker(QThread):
def __init__(self, do_create_data=True, parent=None):
super(QThread, self).__init__()
self.do_create_data = create_data
def run(self):
if self.create_data:
self.create_data()
else:
self.upload_data(), depends