In my python script I want to repeat a function every N minutes, and, of course, the main thread has to keep working as well. In the main thread I have this:
# something
# ......
while True:
# something else
sleep(1)
So how can I create a function (I guess, in another thread) which executes every N minutes? Should I use a timer, or Even, or just a Thread? I'm a bit confused.
use a thread
import threading
def hello_world():
threading.Timer(60.0, hello_world).start() # called every minute
print("Hello, World!")
hello_world()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With