The following script shows the x variable every 3 seconds, while the xx class running on a thread increases the value of x every second. I would like, when the value of x reaches 13, the thread where the xx class is being executed would stop.
from threading import Thread
from time import sleep
class xx(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
global x
while True:
x+=1
sleep(1)
def stop(self):
#O que botar aqui para parar a execução da thread?
def play(self):
#O que botar aqui para iniciar a thread depois de pausada?
x=0
instx=xx()
instx.start()
while True:
sleep(3)
print(x)
if x==13:
instx.stop()
But I do not know what to put in the stop (self) and play (self) methods to pause and resume thread execution. How can I do this?