Python 时间延迟 [英] Python Time Delays
本文介绍了Python 时间延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何在一段时间后调用函数.我试过 time.sleep() 但这会停止整个脚本.我希望脚本继续运行,但在 ???secs 调用一个函数并同时运行另一个脚本之后
I want to know how to call a function after a certain time. I have tried time.sleep() but this halts the whole script. I want the script to carry on, but after ???secs call a function and run the other script at the same time
推荐答案
看看 threading.Timer
.它在新线程中运行您的函数.
Have a look at threading.Timer
. It runs your function in a new thread.
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 时间延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文