Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My solution to Excercise #2 at http://krondo.com/?p=1333
#! /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