尝试了不少写法,有各类timer的trick,也有结合sched来作的(感受实际上是穿一条裤子的)。最后仍是以为这个略有点二的写法比较实用。code
import threading def say_sth(str): print str t = threading.Timer(2.0, say_sth,[str]) t.start() if __name__ == '__main__': timer = threading.Timer(2.0,say_sth,['i am here too.']) timer.start()
不清楚在某些特殊应用场景下有什么缺陷否。thread