In the example below the timer will keep printing hello world
every 5 seconds and never stop, how can I allow the timer thread to function as a timer (printing 'hello world') but also not stop the progression of the program?
import threading
class Timer_Class(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
self.running = True
def run(self, timer_wait, my_fun, print_text):
while self.running:
my_fun(print_text)
self.event.wait(timer_wait)
def stop(self):
self.running = False
def print_something(text_to_print):
print(text_to_print)
timr = Timer_Class()
timr.run(5, print_something, 'hello world')
timr.stop() # How can I get the program to execute this line?