Timer

Alan Kennedy alanmk at hotmail.com
Mon Oct 27 07:54:09 EST 2003


[Derek Fountain]
> Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
> this bit of code" sort of thing?

Like this?

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
import threading

def hello():
    print "hello, world"

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

Timers start a new thread of execution.

More info from here

http://www.python.org/doc/current/lib/timer-objects.html

HTH,

-- 
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan




More information about the Python-list mailing list