Skip to content Skip to sidebar Skip to footer

Resettable Timer In Python Repeats Until Cancelled

I have copied the code from this webaddress http://code.activestate.com/recipes/577407-resettable-timer-class-a-little-enhancement-from-p/ To create a resettable timer, and it work

Solution 1:

Change the run function to:

defrun(self):
    whilenot self.finished.isSet():
        print"Time: %s - timer running..." % time.asctime()

        self.resetted = Truewhile self.resetted:
            print"Time: %s - timer waiting for timeout in %.2f..." % (time.asctime(), self.interval)
            self.resetted = False
            self.finished.wait(self.interval)

        ifnot self.finished.isSet():
            self.function(*self.args, **self.kwargs)
    print"Time: %s - timer finished!" % time.asctime()

This will cause it to run indefinitely until finished is set.

Post a Comment for "Resettable Timer In Python Repeats Until Cancelled"