Mikael
Mikael

Reputation: 554

How to run a function repeatedly with a fixed delay using Python?

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?

Upvotes: 0

Views: 227

Answers (1)

spicypumpkin
spicypumpkin

Reputation: 1219

import time

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

Try it!

Upvotes: 1

Related Questions