Python 线程(六):Timer(定时器)

Timer:  隔一定时间调用一个函数,如果想实现每隔一段时间就调用一个函数的话,就要在Timer调用的函数中,再次设置Timer。Timer是Thread的一个派生类

 1 import threading
 2 import time
 3 
 4 def hello(name):
 5     print "hello %s
" % name
 6 
 7     global timer
 8     timer = threading.Timer(2.0, hello, ["Hawk"])
 9     timer.start()
10 
11 if __name__ == "__main__":
12     timer = threading.Timer(2.0, hello, ["Hawk"])
13     timer.start()
原文地址:https://www.cnblogs.com/wang-can/p/3582051.html