[Twisted-Python] Returning a DeferredList?
nathan.stocks at gmail.com
Tue Jul 1 12:19:16 EDT 2008
On Mon, Jun 30, 2008 at 8:02 PM, L. Daniel Burr <ldanielburr at mac.com> wrote:
> On Mon, 30 Jun 2008 17:54:33 -0500, Nathan <nathan.stocks at gmail.com> wrote:
>> On Mon, Jun 30, 2008 at 4:20 PM, Terry Jones <terry at jon.es> wrote:
>>> You're not using deferreds properly. In the simple/typical case, when you
>>> call a function that returns a deferred, you will want to add (at least)
>> I don't think that's true. Jean-Paul was the one who told me to do it
>> that way in the first place:
> Terry (hi Terry) is correct here. Your interpretation of Jean-Paul
> Calderone's message is flawed, although I certainly understand how
> the misinterpretation could occur. There's a big difference between
> the AMP example in that thread, and the example code you posted to
> this thread.
Oh, ok. My apologies, Terry. After staring for awhile I think I
figured out what's going on. First, everywhere I use this method in
real code is to provide a final AMP response (which is why it works
for me). I think what Jean Paul meant was that the AMP code looks at
the object that the AMP responder returns, and if that object is a
deferred, then the underlying AMP code (that you don't normally see)
waits for the deferred's callback value and uses that as the actual
return value of the AMP responder. I had mistakenly taken this as a
more general method of
returned-deferreds-resolving-into-their-callback-values, which is why
everyone is taking issue with my hasty AMP-less pseudo-code.
I must say, I've had more trouble grasping the nuances of deferreds
and other twisted objects than any other framework or language I've
ever worked with. I also spend much more time _in vain_ going through
the docs and api reference than other languages. At least there's a
great mailing list!
So back to my original task -- I'm trying to get that same behaviour
in AMP when using a deferred list -- but I could probably just create
a deferred and return it as the AMP response (because AMP will wait
for the deferred's callback value), and then fire a callback with my
correct answer once I've processed my deferred list. Thus, I could
avoid figuring out how AMP handles
Have I got it straight now?
More information about the Twisted-Python