SHARE
TWEET

Untitled

a guest Jun 26th, 2013 11 Never
  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()
RAW Paste Data
Top