Issue 28725: Awaiting an awaitable returned from an async function does nothing (original) (raw)

Issue28725

Created on 2016-11-17 15:43 by allenap, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg281043 - (view) Author: Gavin Panella (allenap) Date: 2016-11-17 15:43
The following will sleep: async def one(): await asyncio.sleep(10) async def two(): await one() loop.run_until_complete(two()) but the following will not: async def one(): return asyncio.sleep(10) async def two(): await one() loop.run_until_complete(two()) I would expect run_until_complete to keep bouncing awaitable results back into the event-loop until a non-awaitable is returned. In my code I work around this with: result = loop.run_until_complete(...) while inspect.isawaitable(result): result = loop.run_until_complete(result) I would also expect that the await in `two` would have DTRT with the returned generator/coroutine.
msg281055 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2016-11-17 17:02
This isn't a bug. Python doesn't magically unwind awaitables, you have to do that yourself: async def two(): await (await one()) Broadly speaking, returning awaitables from coroutines is an anti-pattern. Closing this one. Feel free to re-open or ask questions :)
History
Date User Action Args
2022-04-11 14:58:39 admin set github: 72911
2016-11-17 17:02:49 yselivanov set status: open -> closedresolution: not a bugmessages: + stage: resolved
2016-11-17 15:43:29 allenap create