Timer hangs when quitting app

G

Gitte Wange

Hello,

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.

Any hint will be appreciated :)

Greetings,
Gitte Wange
 
P

Peter Hansen

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

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top