[Python-Dev] async/await in Python; v2 (original) (raw)
Greg Ewing greg.ewing at canterbury.ac.nz
Thu Apr 23 09:36:23 CEST 2015
- Previous message (by thread): [Python-Dev] async/await in Python; v2
- Next message (by thread): [Python-Dev] async/await in Python; v2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Victor Stinner wrote:
A huge part of the asyncio module is based on "yield from fut" where fut is a Future object.
How do you write this using the PEP 3152? Do you need to call an artifical method like "cocall fut.returnself()" where the returnself() method simply returns fut?
In a PEP 3152 world, Future objects and the like would be expected to implement cocall, just as in a PEP 492 world they would be expected to implement await.
@asyncio.coroutine currently calls a function and then check if it should yields from it or not:
res = func(*args, **kw) if isinstance(res, futures.Future) or inspect.isgenerator(res): res = yield from res
To accommodate the possibility of func being a cofunction, you would need to add something like
if is_cofunction(func):
res = yield from costart(func, *args, **kw)
else:
# as above
-- Greg
- Previous message (by thread): [Python-Dev] async/await in Python; v2
- Next message (by thread): [Python-Dev] async/await in Python; v2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]