[Python-ideas] Async API: some more code to review
Guido van Rossum
guido at python.org
Tue Oct 30 15:52:51 CET 2012
On Mon, Oct 29, 2012 at 7:29 PM, Yury Selivanov <yselivanov.ml at gmail.com> wrote:
> Couple of things I like already:
>
> 1) Use of 'yield from' is completely optional
That's actually my biggest gripe...
> 2) @async decorator. That makes coroutines more visible and
> allows to add extra methods to them.
Yes on marking them more visibly. No on wrapping each call into an
object that slows down the invocation.
> 3) Tight control over coroutines execution, something that
> is completely missing when you use yield-from.
This I don't understand. What do you mean by "tight control"? And why
would you want it?
> I dislike the choice of name for 'async', though. Since
> @async-decorated functions are going to be yielded most of the
> time (yield makes them "sync" in that context), I'd stick to
> plain @coroutine.
Hm. I think of it this way: the "async" (or whatever) function *is*
asynchronous, and just calling it does *not* block. However if you
then *yield* (or in my tulip proposal *yield from*) it, that suspends
the current task until the asyc function completes, giving the
*illusion* of synchronicity or blocking. (I have to admit I was
confused by a comment in Steve's example code saying "does not block"
on a line containing a yield, where I have been used to think of such
lines as blocking.)
> P.S. If this approach is viable (optional yield-from, required
> @async-or-something decorator), I can invest some time and
> open source the core of my framework (one benefit is that it
> has lots and lots of unit-tests).
Just open-sourcing the tests would already be useful!!
--
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas
mailing list