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

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

 

 1 import threading
 2 import time
 3 
 4 def hello(name):
 5     print "hello %s\n" % 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()

 

posted @ 2014-03-05 11:26  Fly Hawk  阅读(55572)  评论(0编辑  收藏  举报