Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-Threading in PyQt 5

I've been learning about multi-threading, specifically in the context of a PyQt 5 application.

Initially I implemented a version using 'threading', but have since learnt that I should be using 'QThread' to allow use of signals / slots, e.g:

workerThread = QThread()
workerObject = Worker(cmdlist)
workerObject.moveToThread(workerThread)
workerThread.started.connect(workerObject.run)
workerObject.finished.connect(workerThread.quit)

However, is it possible to design a system in which:

  • Each class is associated with a thread created at run-time.
  • The'main' component of the program can then call functions within those classes, which are executed within the separate thread for the given class.

An example of the behaviour would be this:

thread = threading.Thread(target=self.run, args=())

But how would I implement similar behaviour with QThread?
Or my understanding of threads in Python in-correct?

like image 748
Masutatsu Avatar asked Dec 09 '25 11:12

Masutatsu


1 Answers

Martin Fitzpatrick has an amazing guide on how to do this using QThreadPools. I think this is what you're looking for.

Multithreading PyQt applications with QThreadPool

like image 99
daegontaven Avatar answered Dec 11 '25 02:12

daegontaven



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!