0

I have a function f()that I want to run from time to time, let's say each 10 seconds. My goal is to run it indefinitely, only being killed by a interrupt. I looked into the sched module, but couldn't find how to run the function repeatedly ad infinitum. Maybe a while True loop?

2
  • 2
    I think you just need the time module with time.sleep(10) in a while True loop, unless your requirement is more complicated than you have explained in the question. Note that this will give a 10 second pause after each function call, but will not take into account how long the function itself takes to execute. Commented Mar 28, 2017 at 19:06
  • I would you a loop, with sleep function, e.g. from time import sleep sleep(0.1) # Time in seconds Commented Mar 28, 2017 at 19:07

1 Answer 1

1
import time

while True:
    f()
    time.sleep(10)

Try it!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.