Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 26th, 2013  |  syntax: Python  |  size: 0.66 KB  |  views: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from twisted.internet import defer, reactor
  2.  
  3.  
  4. def startWithMe(ignore):
  5.  
  6.     messages = ["hello", "everyone", "end"]
  7.  
  8.     def andMe(ignore):
  9.         if messages:
  10.             print "M:", messages.pop()
  11.             d = defer.Deferred()
  12.             d.addCallback(andMe)
  13.             reactor.callLater(0.5, d.callback, 1)
  14.             return d
  15.  
  16.     d1 = defer.Deferred()
  17.     reactor.callLater(0.5, d1.callback, 1)
  18.     return defer.DeferredList([andMe(None), d1], fireOnOneErrback=True)
  19.  
  20. def endWithMe(ignore):
  21.     print ignore, ";This is the end."
  22.  
  23. d = defer.Deferred()
  24. d.addCallback(startWithMe)
  25. d.addCallback(endWithMe)
  26.  
  27. d.callback(1)
  28. reactor.run()