我在 Windows 上工作。我想每 10 秒执行一次函数 foo()
。
我该怎么做?
最佳答案
在 foo()
结束时,创建一个 Timer
,它会在 10 秒后调用 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 2011
#Thu Dec 22 14:46:18 2011
#Thu Dec 22 14:46:28 2011
#Thu Dec 22 14:46:38 2011
关于python - 执行周期性 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8600161/