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()