[Twisted-Python] Returning a Deferred as a result from another Deferred

Jean-Paul Calderone exarkun at divmod.com
Tue Oct 9 06:12:49 EDT 2007


On Mon, 8 Oct 2007 22:59:49 -0700, Ryan Fugger <rfugger at gmail.com> wrote:
>On 10/8/07, Jean-Paul Calderone <exarkun at divmod.com> wrote:
>> On Fri, 5 Oct 2007 19:00:51 -0700, Ryan Fugger <rfugger at gmail.com> wrote:
>> >On 10/5/07, Jonathan Lange <jml at mumak.net> wrote:
>> >> On 10/6/07, Ryan Fugger <rfugger at gmail.com> wrote:
>> >> > Returning a Deferred as a result from another Deferred seems to be
>> >> > disallowed by an assertion at the start of the callback chain.
>>
>> You've misread the code.  Jonathan is correct.
>
>What is that assertion guarding against then?  Seems to me like it is
>explicitly preventing you from doing this:
>
>d1 = Deferred()
>d2 = Deferred()
>d1.callback(d2)
>
>In fact, that exact code raises the AssertionError in question.  If
>the intention is to allow this, then the assertion needs to be
>removed.

Here's what it sounds like "returning a Deferred as a result from another
Deferred" describes:

    def f(result):
        return Deferred()

    d = Deferred()
    d.addCallback(f)
    d.callback(None)

This is a useful and very common thing to do.  I see this isn't what you
were attempting to describe now, though.

Jean-Paul




More information about the Twisted-Python mailing list