-1

I wanted to use while loop to keep executing my script over and over but there is a problem as my code calls an API that doesn't allow so many calls in small time so I wanted to make the while loop be executed at time interval so I tried this code

from threading import Timer
def myfunc():
   some code
while True:
   t = Timer(1.0, myfunc)
   t.start()

but it doesn't work, so is there any other way to do it correctly?

1 Answers1

1

Use the time module:

import time

def myfunc():
   some code

while True:
   myfunc()

   # unit is in second. Example below wait for 1 second before continuing
   time.sleep(1)

Toukenize
  • 1,390
  • 1
  • 7
  • 11