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.

1:1 Coaching & Tutoring for your Python GUIs project
Martin Fitzpatrick Python GUIs Coaching & Training
60 mins ($195) Book Now

1:1 Python GUIs Coaching & Training

Comprehensive code reviewBugfixes & improvements • Maintainability advice and architecture improvements • Design and usability assessment • Suggestions and tips to expand your knowledgePackaging and distribution help for Windows, Mac & Linux • Find out more.


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.

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

More info Get the book

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 https://www.martinfitzpatrick.com/browse/books/ on the subject.