Answers for "how to run a function in interval in python"

2

how to run a function in interval in python

# This runs test() function in intervals of 1 second
from threading import Timer
run = True
def test():
	global run
	print("something")
	if run:
		Timer(1, test).start()

test()
# now whenever you set run to False the test function won't run anymore
# and of course if you dont set it to False it will run forever
Posted by: Guest on December-22-2020
3

how to run a function in interval in python

# this makes program sleep in intervals
from time import time, sleep
while True:
    sleep(1 - time() % 1) # run every 1 second... you can change that
	# thing to run
Posted by: Guest on December-22-2020

Code answers related to "how to run a function in interval in python"

Python Answers by Framework

Browse Popular Code Answers by Language