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?
Aucun commentaire:
Enregistrer un commentaire