[Python-ideas] gevent-like Coroutines in Python
greg.ewing at canterbury.ac.nz
Tue Oct 30 05:34:10 EDT 2018
Ron Reiter wrote:
> I feel like having the await syntax trigger by default on any awaitable
> invocation in a coroutine context makes much more sense.
Guido seems to regard the requirement to use 'await' as a
feature, not a bug. He says he likes to be able to see where
all the potential suspension points are.
> Therefore, my suggestion is to create a new "async" definition which
> basically turns every function invocation into an "await" if a generator
> is returned. Instead of "async def" I propose the alternative "coroutine
> def" syntax. However, a better solution may be to imply the word "async"
> in every function definition given some sort of trigger (however I
> assume that this won't be the preferable approach as it is not something
> that can be implemented at the parsing level).
I don't think it's feasible to automatically infer both 'async'
*and* 'await', even at run time. An async function needs to be
treated differently from the moment it starts running, so there
must be something that statically identifies it as such.
Anyway, if you want to pursue these ideas further, you should
take a look at PEP 3152, which was my attempt at a nicer syntax
for generator-based coroutines, before async/await came along.
I think it would have been better in some ways, but it was
More information about the Python-ideas