[Python-ideas] The async API of the future: yield-from
Guido van Rossum
guido at python.org
Fri Oct 19 22:22:55 CEST 2012
Jim, relax.
We're not changing the meaning of yield or generator.
We're just making it *possible* to use yield(-from) and generators as
coroutines; that's actually a long path that started with PEP 342. No
freedom is taken away by PEP 380; it just adds the possibility to do
it without managing an explicit stack of coroutine calls in the
scheduler.
If we believed that there was no advantage to spelling a blocking call
as "yield from foo()", we would just spell it as "foo()" and somehow
make it work.
But (and even Christian Tismer agrees) there is a problem with the
shorter spelling -- you lose track of which calls may cause a
task-switch. Using yield-from (or yield, for that matter) for this
purpose ensures that all callers in the call chain have to explicitly
mark the suspension points, and this serves as a useful reminder that
after resumption, the world may look differently, because other tasks
may have run in the mean time.
--
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas
mailing list