Page 1 of 1

Using Timer function

Posted: Sat Mar 09, 2013 9:33 pm
by nisseb
Im learning Pyton and now like to control my timeflow. Using the tutorial at http://docs.python.org/2/library/thread ... -threading part 16.2.7 would help me, but it do not work. I do exactly as it says in the text but the command Timer seems not to be know to my system. Have tried to find how to import this (import Timer, import thread etc) but no sucess...

Re: Using Timer function

Posted: Sat Mar 09, 2013 10:07 pm
by KenT
A quick Google suggests

Code: Select all

import threading

def hello():
print "hello, world"

t = threading.Timer(30.0, hello)
t.start() # after 30 seconds, "hello, world" will be printed

Re: Using Timer function

Posted: Sat Mar 09, 2013 10:31 pm
by nisseb
Thanks - that solved the problem.
The code in the tutorial said:

Code: Select all

def hello():
    print "hello, world"

t = Timer(30.0, hello)
t.start() # after 30 seconds, "hello, world" will be printed
My googling for several hours did not tell that "Timer" should be replaced by "threading.Timer". Your google was faster :-)