Timer hangs when quitting app

Peter Hansen peter at engcorp.com
Sun Nov 28 12:31:49 EST 2004


Gitte Wange wrote:
> I'm trying to create an application that needs a Timer() to do various
> checks.
> My class has a self.timer = Timer(900, self.sendDNSRequest)
> The timer itself works fine but whenever I try to exit the application, it
> simply hangs and I have to kill the proces using `kill pid`
> 
> I have tried uncommenting the timer stuff, and then the app works as
> expected.
> 
> Is there anything I need to do to kill the timer?
> I have tried to create a __del__(self) function in my app. It gets called
> when I leave out the timer, but with the timer enabled, it never gets
> called.

A Timer is a subclass of threading.Thread, which means
you can do "self.timer.setDaemon(True)" on it *before*
you start it, and it will not hang the app when it
is trying to exit.

See notes in the threading module's Thread.setDaemon
docs for background.

-Peter



More information about the Python-list mailing list