timer problem

Diez B. Roggisch deets.nospaaam at web.de
Thu Aug 19 08:57:09 EDT 2004


flupke wrote:
> Now, when i run it, it only prints TIMER CALLED once instead
> of every 2 seconds.
> What am i doing wrong? (Python 2.3.4 on Win2000)


You assume that Timer is looping - it isn't. So make your command start a
Timer itself, like this:

def command():
    print "called"
    t = threading.Timer(2, command )
    t.start()


Or use a Thread, with an endless loop in the run()-method that sleeps for
two secdonds. That spares you the overhead of thread-creation.

Regards,

Diez



More information about the Python-list mailing list