How to start/stop or pause running threads?

Heads up! You've already completed this tutorial.

Pshemas | 2020-05-11 07:17:31 UTC | #1

Nice article. I have question, it is possible use this template for function which we start by pressing button and break by pressing another button?

https://www.pythonguis.com/courses/concurrent-execution/multithreading-pyqt-applications-qthreadpool/


anonymous | 2020-05-10 21:32:56 UTC | #2

I would like to ask for help with stopping thread (as Pshemas did some time ago). I have tried to add signal stop but I do not know how to emit that.


Alex | 2020-05-11 07:16:33 UTC | #3

I wrote a program using this article. But I do not know how to pause or stop all processes. Please, help.

Create GUI Applications with Python & Qt6 by Martin Fitzpatrick — (PyQt6 Edition) The hands-on guide to making apps with Python — Over 15,000 copies sold!

More info Get the book


luciano | 2020-05-11 07:18:18 UTC | #4

Hi, I'm working on a data sample and plot GUI, which communicates with an external device, I've read the tutorial and helps me a lot. The issue is how to handle start and stop QRunnable in follow to start and stop communication engine.


Steven_K_Peters | 2020-11-16 20:54:11 UTC | #5

In my code, my thread uses a while loop. So what I did is I created a variable called self.active = True inside class Worker which is used to control the while loop (while active). When I want the loop to stop I simply call worker.active=False and I make sure to set worker.setAutoDelete(True) so the thread is deleted automatically upon exit.

Over 15,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt5
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]

To make a thread pause I'm thinking you could place a while loop with argument self.pause=True. while self.pause: time.sleep(1)

I'm not sure if you would like my pause solution, but it's an option.


martin | 2020-11-16 20:54:11 UTC | #6

There is a working example of Steven's idea on this topic with a pause/resume/stop methods added to the worker.

Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book


Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak
Martin Fitzpatrick

How to start/stop or pause running threads? was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular Python books on the subject.