I have two functions: foo() should start every 5 seconds and bar() should start every 10 seconds. code below:
import threading
import time
def foo():
while True:
time.sleep(5)
print("Call every 5 seconds")
time.sleep(5)
def bar():
while True:
time.sleep(10)
print("Call every 10 seconds")
tr1 = threading.Thread(target=foo)
tr1.start()
tr2 = threading.Thread(target=bar)
tr2.start()
But I think that this is not a good solution. What is the best way to do this? And yes, I think that I have memory leak, should I use garbage collector or anything else?
P.S. I hope you could understand what i wrote, because I am not native speaker.