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 ;-) |