Python Time Delays

Viewed 57728

I want to know how to call a function after a certain time. I have tried time.sleep() but this halts the whole script. I want the script to carry on, but after ???secs call a function and run the other script at the same time

4 Answers

If the non-block feature is not needed, just use time.sleep(5) which will work anywhere and save your life.

Okey, not a perfect solution but i used the following since my job was simple enough:

counter_time = 0
while True:
   time.sleep(0.1)
   counter_time = counter_time + 0.1

Now you have time just use if to do something at spesific time. My code was running inside the while loop so this worked for me. You can do the same or use threading to run this infinite loop together with your own code.

Related