繁体   English   中英

python threading.Timer不会在指定时间立即启动

[英]python threading.Timer start immediately not at specified time

如果我调用一个没有如下参数的函数,我想每隔3秒执行一次函数代码:

def mytempfunc():
    print "this is timer!"
    threading.Timer(5, mytempfunc).start()

但如果我用这样的参数调用一个函数:

def myotherfunc(a,b,c,d):
    print "this is timer!"
    threading.Timer(5, myotherfunc(a,b,c,d)).start()

新线程将立即创建并启动,无需等待5秒钟。 有什么我错过的吗?

尝试这个:

threading.Timer(5, myotherfunc, [a,b,c,d]).start()

在您的代码中,您实际上调用myotherfunc(a,b,c,d),而不是将函数和参数传递给Timer类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM