I have this class which is my thread. By creating instance of the class I create my thread, so by calling its stop method it should be terminated or killed but it wouldn't. I don't know why? I appreciate if someone can help me.
class MyThread(threading.Thread):
# Thread class with a _stop() method.
# The thread itself has to check
# regularly for the stopped() condition.
def __init__(self, last_time=0, start_time=0, label="", root="", speed_mode=""):
super(MyThread, self).__init__()
self.label = label
self.last_time = last_time
self.start_time = start_time
self.root = root
self.speed_mode = speed_mode
self._stop_event = threading.Event()
# function using _stop function
def start_counter(self):
self.start_time += 1
self.label['text'] = self.start_time
# self.start_time = start_time
if self.start_time < self.last_time:
self.label.after(DIC_TIME[self.speed_mode], self.start_counter)
def stop(self):
self._stop_event.set()
def stopped(self):
return self._stop_event.isSet()
def run(self):
self.start_counter()
while True:
if self.stopped():
return
I expect that by calling stop method of MyThread class my label in tinter canvas restart and stop running(label is a second counter)