Skip to content

Instantly share code, notes, and snippets.

Created August 23, 2012 06:18
Show Gist options
  • Save anonymous/3433337 to your computer and use it in GitHub Desktop.
Save anonymous/3433337 to your computer and use it in GitHub Desktop.
krondoEx3-2
from twisted.internet.task import LoopingCall
counters = [6, 5, 4]
times = [1, 2, 3]
class Countdown(object):
instances = 0
def __init__(self, countFrom, interval):
self.counter = countFrom
self.lc = LoopingCall(self.count)
Countdown.instances += 1
self.instanceNum = Countdown.instances
self.lc.start(interval)
def count(self):
if self.counter == 0:
print 'Stop %s' % self.instanceNum
self.lc.stop()
Countdown.instances -= 1
if Countdown.instances == 0:reactor.stop()
else:
print 'instance %s: count %s' % (self.instanceNum, self.counter), '...'
self.counter -= 1
from twisted.internet import reactor
reactor.callWhenRunning(map, Countdown, counters, times)
print 'Start!'
reactor.run()
print 'Stop!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment