threading.Timer newbie question

Peter Hansen peter at engcorp.com
Tue Oct 14 12:54:21 EDT 2003


berklee just berklee wrote:
> 
> When you call a timer, like in the documentation:
> def hello():
>     print "hello, world"
> 
> t = Timer(30.0, hello)
> t.start() # after 30 seconds, "hello, world" will be printed
> Does the thread get destroyed after the task is done? I mean, if I set up an
> ongoing monitor and use timers to watch over jobs, do I have to worry about
> thread management?

The best way to answer such questions is to check the source
(in threading.py).

In this case, in threading._Timer(), you can see that the run()
method simply waits for the required amount of time, calls the
function, calls .set() on the Event object it holds, then 
finishes.  Since _Timer is simply a subclass of _Thread, you
can count on it behaving the way a regular thread would (which
is, it will be destroyed, assuming regular threads get destroyed
on your platform...).

-Peter




More information about the Python-list mailing list