So I want to make a loop like this (example simplified):
def main():
while True:
function1() #run this every 1s
function2() #run this every 2s
function3() #run this every 5s
function4() #run this every 10s
Ideally, after 10s it should run function1 10 times, function2 5 times, function3 2 times,..etc.
My current approach is using a loop counter but it's far from ideal since the time spent for each loop is not accounted and is not constant.
def main():
while True:
loop_counter = loop_counter + 1
if loop_counter % 2 == 0: function1()
if loop_counter % 4 == 0: function2()
if loop_counter % 10 == 0: function3()
if loop_counter % 20 == 0: function4()
#this assumes each loop take 0.5s to run
I'm new to python so any guidance is appreciated.
threading.Timerscheduleshould be able to do this well.