gagsl-py2 at yahoo.com.ar
Tue Jun 3 04:11:56 CEST 2008
En Fri, 30 May 2008 22:50:13 -0300, Robert Dailey <rcdailey at gmail.com>
> Reading through the Python 2.5 docs, I'm seeing a Timer class in the
> threading module, however I cannot find a timer object that will
> continuously call a function of my choice every XXXX amount of
> For example, every 1000 milliseconds I want a function named Foo to be
> called. This would continue to happen until I terminate the timer in my
> thread. Thanks for the help.
Use an Event object; its wait() will provide the sleep time, and when it
is set() the thread knows it has to exit.
def repeat(event, every, action):
print "I'm bored to death..."
print "creating event and thread"
ev = threading.Event()
t1 = threading.Thread(target=repeat, args=(ev, 1.0, foo))
print "starting thread"
print "waiting for 10 seconds in main thread"
print "setting event"
print "waiting for thread to finish"
More information about the Python-list