Home >Backend Development >Python Tutorial >How to Execute a Function Periodically in Windows Using the Timer Class?
Executing Periodic Actions
Executing specific functions at regular intervals is a common task in programming. In Windows, there are multiple methods to achieve this, one of which involves utilizing the Timer class.
To execute a function, such as foo(), every 10 seconds, the following approach can be implemented:
import time, threading def foo(): print(time.ctime()) # Create a Timer to call foo() again after 10 seconds threading.Timer(10, foo).start() foo()
The above is the detailed content of How to Execute a Function Periodically in Windows Using the Timer Class?. For more information, please follow other related articles on the PHP Chinese website!