[Twisted-Python] waitForDeferred Question

Christopher Armstrong radeex at gmail.com
Sat Mar 11 13:58:06 EST 2006

On 3/11/06, Brian Granger <bgranger at scu.edu> wrote:
> Regardless of whether or not I should *want* to do this (get the
> result of a Deferred() in a manner the *appears* synchronous) there is
> a question that remains:
> Can it be accomplish using waitForDeferred?  The docstring seems to
> imply that it can, but it is not clear.
> If so, could someone provide an working example.
> Just a side note, I seem to recall Guido has even citing this type of
> usage scenario as one of the motivations for improving generators.

waitForDeferred really can't do this for you. I hope that the
docstring is clear enough to show that it really requires special
syntax every time you want to wait for a Deferred.

As far as the improved generators in the upcoming release of Python,
they *still* would require you to have special syntax when you want to
wait for a Deferred, but it's fewer lines of code.

I think what other people have suggested, about just having your UI
handle Deferreds specially, is the way to go. Of course, >>> 3 *
fetchDeferred() will be a quite difficult thing to do. I'm not sure if
it'd be possible at all with Python itself, so you may just end up
exposing some minilanguage other than Python to your end users. You
*might* be able to do some weird hacks with trace hooks or something
to do it in Python, but I'm not certain.

Christopher Armstrong
International Man of Twistery

More information about the Twisted-Python mailing list