threading.Timer newbie question

  • Thread starter berklee just berklee
  • Start date
B

berklee just berklee

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?
 
P

Peter Hansen

berklee said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top