python3.x: Simple Time scheduling timer (interval execution)
Code:
ImportThreadingImport TimedefFun_timer ():Print('Hello Timer') GlobalTimer#Repeating Construction TimerTimer = Threading. Timer (5.8, Fun_timer) Timer.start ()#Timing SchedulingTimer = Threading. Timer (2, Fun_timer) Timer.start ()#Stop timer after 50 secondsTime.sleep (50) Timer.cancel ()
Description
(1). Threading.timer () There are 2 main parameters: The first parameter is the time, the second parameter is the function name;
(2). The timer must be repeatedly constructed within the timer execution function, since the timer is constructed only 1 times and must be called in a loop;
(3). The Timer interval unit is the second, can be a floating point number, such as 5.5,0.02, such as the first time the Fun_timer is executed after 2 seconds, the back is 5.8 seconds after the execution.
(4). Use Cancel to stop the timer work;
python3.x: Simple Time scheduling timer (interval execution)