[Twisted-Python] Oddity(?) with zero-length Deferred lists

Gregg Lind gregg at renesys.com
Fri May 9 13:33:19 MDT 2008


Good afternoon!

I notice an oddity with zero-length DeferredLists.

The example script (http://dpaste.com/49099/) should just return the 
contents of a bunch of URLs given at the command line, or some errors 
like so:

$ python test.py a b c
[(False, <twisted.python.failure.Failure twisted.web.error.Error>), 
(False, <twisted.python.failure.Failure twisted.web.error.Error>), 
(False, <twisted.python.failure.Failure twisted.web.error.Error>)]

*but*

$ python test.py     # no arguments
[]
# then hangs, never reaching "quit"


Is this odd behaviour?   In defer.py 's  DeferredList.__init__ there is:

       self.resultList = [None] * len(deferredList)
       Deferred.__init__(self)
       if len(deferredList) == 0 and not fireOnOneCallback:
           self.callback(self.resultList)


Thanks in advance!

Gregg


------------------------
#!/usr/bin/env python
## example script1
from twisted.web.client import getPage
from twisted.internet import reactor, defer

def getUrls(L):
   dL = defer.DeferredList( [getPage(x) for x in L] , consumeErrors=True)
   return dL

def results(data):
   print data
   return
  def quit(data):
   reactor.stop()
   return
  if __name__ == "__main__":
   import sys
   L = sys.argv[1:]
   d = getUrls(L)
   d.addCallback(results)
   d.addCallback(quit )
   reactor.run()




More information about the Twisted-Python mailing list