[issue36222] ValueError: a coroutine was expected with asyncio.run
STINNER Victor
report at bugs.python.org
Thu Mar 7 04:30:54 EST 2019
STINNER Victor <vstinner at redhat.com> added the comment:
asyncio.run() requires a coroutine, whereas gather() returns a subclass of asyncio.Future.
https://docs.python.org/dev/library/asyncio-task.html#asyncio.run
You can wrap gather() into a coroutine like that:
---
async def main():
await asyncio.gather(mocked_function())
asyncio.run(main())
---
loop.run_until_complete() is different. It requires a "future", not a coroutine.
https://docs.python.org/dev/library/asyncio-eventloop.html#asyncio.loop.run_until_complete
gather() creates a future which is linked to the current event loop, whereas asyncio.run() creates a new event loop for the lifetime of run(). You should not pass a Future from an event loop to another event loop.
It's not a bug ;-)
----------
nosy: +vstinner
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36222>
_______________________________________
More information about the Python-bugs-list
mailing list