[Python-Dev] PEP 3152 and yield from Future()
Greg Ewing
greg.ewing at canterbury.ac.nz
Fri Apr 24 02:02:06 CEST 2015
Victor Stinner wrote:
> I'm still trying to understand how the PEP 3152 would impact asyncio.
> Guido suggests to replace "yield from fut" with "cocall fut()" (add
> parenthesis) and so add a __cocall__() method to asyncio.Future.
> Problem: PEP 3152 says "A cofunction (...) does not contain any yield
> or yield from expressions".
A __cocall__ method doesn't have to be implemented with
a cofunction. Any method that returns an iterator will
do, including a generator. So a Future.__cocall__ that
just invokes Future.__iter__ should work fine.
> How is it possible to suspend a cofunction if it's not possible to use yield?
The currently published version of PEP 3152 is not
really complete. A few things would need to be added
to it, one of them being a suspend() builtin that
has the same effect as yield in a generator-based
coroutine.
--
Greg
More information about the Python-Dev
mailing list