Python--day41--threading中的定时器Timer

定时器Timer:定时开启线程

代码示例:

 1 #定时开启线程
 2 import time
 3 from threading import Timer
 4 
 5 def func():
 6         print('时间同步')   #1-3
 7         #睡5s
 8 
 9 while True:
10     Timer(5,func).start()   #异步的,非阻塞
11     time.sleep(5)

运行结果:

原文地址:https://www.cnblogs.com/xudj/p/10346980.html