Created
July 1, 2011 00:52
-
-
Save mikenerone/1057650 to your computer and use it in GitHub Desktop.
My solution to Excercise #2 at http://krondo.com/?p=1333
This file contains hidden or 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
#! /usr/bin/env python | |
from twisted.internet import reactor | |
from twisted.internet.task import LoopingCall | |
class LoopingCountdown(LoopingCall): | |
_instances = set([]) | |
def __init__(self, counter): | |
LoopingCountdown._instances.add(self) | |
self.counter = counter | |
super(LoopingCountdown, self).__init__(self.count) | |
def count(self): | |
if self.counter == 0: | |
LoopingCountdown._instances.remove(self) | |
self.stop() | |
if not LoopingCountdown._instances: | |
reactor.stop() | |
else: | |
print "{0}...".format(self.counter) | |
self.counter -= 1 | |
print 'Start!' | |
LoopingCountdown(15).start(.5) | |
LoopingCountdown(5).start(1) | |
LoopingCountdown(7).start(2) | |
reactor.run() | |
print 'Stop!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment