Timer runs only once.

vnthmanoharan at gmail.com vnthmanoharan at gmail.com
Thu Dec 1 00:28:42 EST 2016


On Wednesday, 30 November 2016 20:36:15 UTC+5:30, siva gnanam  wrote:
> On Wednesday, November 30, 2016 at 8:11:49 PM UTC+5:30, vnthma... at gmail.com wrote:
> > from threading import Timer
> > 
> > class TestTimer:
> >     def foo(self):
> >         print("hello world")
> >         self.startTimer()
> > 
> >     def startTimer(self):
> >         self.t1 = Timer(5, self.foo)
> >         self.t1.start()
> > 
> > timer = TestTimer()
> > timer.startTimer()
> 
> I think in this example, We are creating Timer object every 5 seconds. So      every time it will span a new Timer. I don't know what happened to the previous timers we created.

It will be garbage collected. The timer object will go out of scope. Python gc is very efficient as it clears the object as and when the obj moves out of scope


More information about the Python-list mailing list