5

i want to execute a function in every 3 second the code works if i call a function without arguments like below:

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

but if i call a function with argument like this:

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

the new thread will be created and started immediately without waiting for 5 seconds. is there anything that i missed?

user1229351
  • 1,985
  • 4
  • 20
  • 24
  • The tabs on this aren't right and your second example is calling mytempfunc, which doesn't seem right. Could you edit your question? – Jacinda May 24 '13 at 19:11
  • Tabs still look off... – Jacinda May 24 '13 at 19:17
  • note: `Timer()` executes the function only once. See [related question you want to call function repeatedly every n seconds](http://stackoverflow.com/q/12435211/4279) – jfs May 24 '13 at 19:27

1 Answers1

19

Try this:

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

In your code, you actually call myotherfunc(a,b,c,d), rather than passing your function and arguments to the Timer class.

Markku K.
  • 3,840
  • 19
  • 20