nisseb
Posts: 4
Joined: Thu Jan 24, 2013 9:52 pm

Using Timer function

Sat Mar 09, 2013 9:33 pm

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...

KenT
Posts: 758
Joined: Tue Jan 24, 2012 9:30 am
Location: Hertfordshire, UK
Contact: Website

Re: Using Timer function

Sat Mar 09, 2013 10:07 pm

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
Pi Presents - A toolkit to produce multi-media interactive display applications for museums, visitor centres, and more
Download from http://pipresents.wordpress.com

nisseb
Posts: 4
Joined: Thu Jan 24, 2013 9:52 pm

Re: Using Timer function

Sat Mar 09, 2013 10:31 pm

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 :-)

Return to “Python”