title: Python - Run multiple functions at different time interval inside loop
body: <p>So I want to make a loop like this (example simplified):</p>
  <pre><code>def main():
   while True:
    function1() #run this every 1s
    function2() #run this every 2s
    function3() #run this every 5s
    function4() #run this every 10s
  </code></pre>
  <p>Ideally, after 10s it should run function1 10 times, function2 5 times, function3 2 times,..etc.</p>
  <p>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.</p>
  <pre><code>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
  </code></pre>
  <p>I'm new to python so any guidance is appreciated.</p>