threading.Timer() and cancel()
#1
Has anybody experience with threading.Timer(). I 'm trying to implement one and I can't get the cancel() call to work.

Basically if an error occurs the error message is displayed for 5 seconds and then the info message I pass to it will be displayed. If I choose to do something else while the error message is displayed. It's info message will be displayed, so I want to cancel the message I passed when setting the error message.

It doesn't work. The timer keeps going. I should point out the isAlive() works, it does get to the cancel().

Code:
def setErrorMessage(self, msg, msg2):
    if (self.timerMsg.isAlive()):
        self.timerMsg.cancel()
        print 'CANCELLED TIMER'
    self.setMessage(msg, 0)
    self.timerMsg = threading.Timer(5, self.setMessage,(self.user_msg[msg2], 2))
    self.timerMsg.start()
Reply
#2
Duh, It works great.

I didn't account for it in the other setMessage() function.
Reply

Logout Mark Read Team Forum Stats Members Help
threading.Timer() and cancel()0