[Twisted-Python] Oddity(?) with zero-length Deferred lists
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,
On Fri, 09 May 2008 14:33:19 -0500, Gregg Lind
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,
), (False, ), (False, )] *but*
$ python test.py # no arguments [] # then hangs, never reaching "quit"
You can do this in a simpler way without involving DeferredList:
>>> from twisted.internet.defer import succeed
>>> from twisted.internet import reactor
>>> d = succeed(None)
>>> d.addCallback(lambda ign: reactor.stop())
Jean-Paul! Thank you for the quick and informative answer! Gregg Jean-Paul Calderone wrote:
On Fri, 09 May 2008 14:33:19 -0500, Gregg Lind
wrote: 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,
), (False, ), (False, )] *but*
$ python test.py # no arguments [] # then hangs, never reaching "quit"
You can do this in a simpler way without involving DeferredList:
from twisted.internet.defer import succeed from twisted.internet import reactor d = succeed(None) d.addCallback(lambda ign: reactor.stop())
> reactor.run() <hang> As you can see from this example, the Deferred already has a result (a Failure) by the time reactor.run() is called. Adding a callback to a Deferred which already has a result (such as succeed(None) or DeferredList([])) calls the callback immediately. So your sample program is trying to stop the reactor before it starts. Then nothing tries to stop the reactor after you actually do start it. If you add an errback to your Deferred, you'll see the problem reported. One solution to this is to use reactor.callWhenRunning(reactor.stop) instead of reactor.stop().
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (2)
-
Gregg Lind
-
Jean-Paul Calderone