how to set interval in python

Solutions on MaxInterview for how to set interval in python by the best coders in the world

showing results for - "how to set interval in python"
Kendall
05 Jan 2018
1# this makes program sleep in intervals
2from time import time, sleep
3while True:
4    sleep(1 - time() % 1) # run every 1 second... you can change that
5	# thing to run
Malena
05 Apr 2018
1# This runs test() function in intervals of 1 second
2from threading import Timer
3run = True
4def test():
5	global run
6	print("something")
7	if run:
8		Timer(1, test).start()
9
10test()
11# now whenever you set run to False the test function won't run anymore
12# and of course if you dont set it to False it will run forever