[Python-ideas] The async API of the future: Twisted and Deferreds

Guido van Rossum guido at python.org
Sun Oct 14 03:35:00 CEST 2012


On Sat, Oct 13, 2012 at 5:59 PM, Itamar Turner-Trauring
<itamar at futurefoundries.com> wrote:
> Explicit suspension is certainly better than hidden suspension, yes. But by
> extension, no suspension at all is best.

When using Deferreds, there are suspension points too. They just
happen whenever a Deferred is blocked. Each next callback has to
assume that the world may have changed.

You may like that better. But for me, 9 out of 10 times, yield-based
coroutines (whether using Futures or PEP 380's yield from) make the
code more readable than the Deferred style. I do appreciate that often
the Deferred style is an improvement over plain callbacks -- but I
believe that explicit-yielding coroutines are so much better than
Deferred that I'd rather base the future standard API on a combination
of plain callbacks and either Futures+yield or yield-from (the latter
without Futures).

I trust that Twisted invented the best possible interface given the
available machinery at the time (no yield-based coroutines at all, and
not using Stackless). But now that we have explicit-yielding
coroutines, I believe we should adopt a style based on those.

Twisted can of course implement Deferred easily in this world using
some form of adaptation, and we should ensure that this is indeed
reasonable before accepting a standard.

Whether it's better to use yield-from <generator> or yield <future>
remains to be seen; that debate is still ongoing in the thread
"yield-from".

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list