在的末尾foo()
,创建一个在10秒后Timer调用foo()
自身的。 因为,Timer创建一个新的thread要调用foo()
。 你可以做其他事情而不会被阻止。
import time, threading
def foo():
print(time.ctime())
threading.Timer(10, foo).start()
foo()
#output:
#Thu Dec 22 14:46:08 2019
#Thu Dec 22 14:46:18 2019
#Thu Dec 22 14:46:28 2019
#Thu Dec 22 14:46:38 2019