Guest User

wangui

a guest
Aug 15th, 2015
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. class Looping(object):
  2. active = 0
  3. def __init__(self, counter, which):
  4. self.counter = counter
  5. self.which = which
  6. self.delay = 0
  7. Looping.active += 1
  8. def __call__(self):
  9. if self.counter <= 0:
  10. print "Finished" , self.which
  11. Looping.active -= 1
  12. if Looping.active <= 0:
  13. reactor.stop()
  14. else:
  15. print self.counter, self.which, "..."
  16. self.counter -= 1
  17.  
  18. from twisted.internet.task import LoopingCall
  19. from twisted.internet import reactor
  20.  
  21. print "Start"
  22. LoopingCall(Looping(5, "First")).start(2)
  23. LoopingCall(Looping(5, "Second")).start(1)
  24. LoopingCall(Looping(5, "Third")).start(0.5)
  25.  
  26. reactor.run()
  27. print "Stop"
Advertisement
Add Comment
Please, Sign In to add comment