Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

how to set 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
Comment

PREVIOUS NEXT
Code Example
Python :: max int value in python 
Python :: factorise expression python 
Python :: check if numpy array is 1d 
Python :: zermelo python 
Python :: How to count occurences of a certain item in a numpy array 
Python :: convert list to string python 
Python :: set_interval() 
Python :: numpy.datetime64 to datetime 
Python :: bulk file name changer in python 
Python :: github black badge 
Python :: pandas dataframe rename column 
Python :: how to print for loop in same line in python 
Python :: python multiply all elements in array by constant 
Python :: normalise min max all columns pandas 
Python :: change tick labelsize matplotlib 
Python :: what is r strip function in python 
Python :: python program to find fibonacci series using function recursion loop 
Python :: python conditional assignment 
Python :: python list to string with spaces 
Python :: datetime to int python 
Python :: drawkeypoints cv2 
Python :: dropping unnamed columns in pandas 
Python :: python check if all dictionary values are False 
Python :: identify prime numbers python 
Python :: install log21 python 
Python :: sort json python 
Python :: python list rotation 
Python :: python display map 
Python :: how to find largest number in array in python 
Python :: python ndarray string array into int 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =