-
-
Save marconi/ca286ba6e48148d8ac02 to your computer and use it in GitHub Desktop.
Countdown using twisted LoopingCall class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.internet import reactor | |
from twisted.internet.task import LoopingCall | |
class Countdown(object): | |
def __init__(self, counter, freq): | |
self.counter = counter | |
self.freq = freq | |
self.lc = LoopingCall(self.count) | |
self.lc.start(self.freq) | |
def count(self): | |
if self.counter == 0: | |
self.lc.stop() | |
reactor.stop() | |
else: | |
print "%s: %s" % (self.freq, self.counter) | |
self.counter -= 1 | |
print 'Start!' | |
Countdown(5, 1) | |
Countdown(6, 2) | |
Countdown(7, 3) | |
reactor.run() | |
print 'Stop!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment