1

Let's say I have a class named Worker that has many methods and some of its methods have for and while loops. Something along these lines:

class Worker:
    def operation1(self):
        for i in range(5000):
            # performs some resource intensive operation 5000 times.

    def operation2(self):
        while some_condition:
            # another resource intensive operation in the while loop

I want to be able to pause the execution of an instance of the class at any given time and then be able to resume it. So this class should be running on one thread and GUI on another thread. The GUI will have two buttons: Pause and Resume that will pause and resume execution accordingly . How to make it happen? The only way I know how to pause execution of a thread is to use the sleep() method, but how to pause it until user resumes it?

blablaalb
  • 173
  • 3
  • 13
  • Not as well-versed in python multithreading as I am in java but perhaps this is what you're looking for? https://docs.python.org/3/library/threading.html#condition-objects – Jeff Aug 27 '20 at 11:41
  • Thank you for the link. Neither I'm well versed in multithreading, especially in python. It seems like this [answer](https://stackoverflow.com/a/33640897/6702744) is based on the conditions that are mentioned on the page you provided, but I was unable to implement it in my code. I'm still trying. – blablaalb Aug 27 '20 at 11:55

0 Answers0