[英]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.