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

use*_*351 3 python multithreading

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

def mytempfunc():
    print "this is timer!"
    threading.Timer(5, mytempfunc).start()
Run Code Online (Sandbox Code Playgroud)

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

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

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

Mar*_* K. 12

试试这个:

threading.Timer(5, myotherfunc, [a,b,c,d]).start()
Run Code Online (Sandbox Code Playgroud)

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