我想知道如何在一段时间后调用函数。我试过 time.sleep() 但这会停止整个脚本。我希望脚本继续运行,但在 ???secs 后调用一个函数并同时运行另一个脚本
最佳答案
看看threading.Timer
.它在新线程中运行您的函数。
from threading import Timer
def hello():
print "hello, world"
t = Timer(30.0, hello)
t.start() # after 30 seconds, "hello, world" will be printed
关于Python 时间延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3433559/