This article mainly introduces the Timer usage of Python regular execution, and analyzes the principles and related usage skills of the Timer module, for more information about how to use Timer for Python scheduled execution, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
The role of Timer in java is also the same. Threads in python provide a subset of java thread functions.
#! /Usr/bin/env python from threading import Timer import time timer_interval = 1 def delayrun (): print 'running' t = Timer (timer_interval, delayrun) t. start () while True: time. sleep (0.1) print 'main running'
T is a Timer object. [It is estimated that a thread is used internally.] the delayrun function is executed one second later than delay.
The time. sleep function is used to pause the main thread for a moment and continue execution.
I hope this article will help you with Python programming.