【发布时间】:2013-05-20 11:20:27
【问题描述】:
我想每 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 秒。 有什么我错过的吗?
【问题讨论】:
-
此选项卡不正确,您的第二个示例是调用 mytempfunc,这似乎不正确。你能编辑你的问题吗?
-
标签仍然看起来不...
-
注意:
Timer()只执行一次函数。见related question you want to call function repeatedly every n seconds
标签: python multithreading