[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: threads (specifically timers) and releasing resources

Tim Golden

3/25/2010 9:57:00 AM

On 25/03/2010 02:31, Alex Hall wrote:
> Okay, I have my program and it has three different modes (there will
> be more than that). Each mode will have a timer attached to it. If the
> mode remains active and the timer runs out, a function specific to
> that mode is called. If that mode is switched away from, however, the
> timer is canceled and a new timer is created for the mode to which the
> user just switched.

I assume you're using Python's threading.Timer objects as you'd discussed
those before. If so, that's basically a threading.Thread in disguise.
In which case, you're going to have to make sure it cleans up after itself,
releasing whatever resources it holds.

Python's reference-count semantics and cyclic gc will take care of
things in the normal way once the timer-thread has completed. But
you'll have to make sure it completes.

> If the latter, is there a way to completely destroy a thread?

No: in Python, a thread has to self-destruct. This is a relatively
FAQ and there are quite a few recipes around. Here's an example of
something which seems to be close to your current needs:

http://code.activestate.com/recipes/464959-resettable-ti...

TJG