asyncio errors in Python
RuntimeWarning: coroutine was never awaited
The coroutine was most likely called without using await
import asyncio async def nested(): return 42 async def main(): # Nothing happens if we just call "nested()". # A coroutine object is created but not awaited, # so it *won't run at all*. nested() asyncio.run(main())
C:\Users\Andrei\asyncio\main.py:10: RuntimeWarning: coroutine 'nested' was never awaited nested() RuntimeWarning: Enable tracemalloc to get the object allocation traceback
To avoid this error you have to call the coroutine through await
import asyncio async def nested(): return 42 async def main(): # Let's do it differently now and await it: print(await nested()) # will print "42". asyncio.run(main())
42
Article author: Andrei Olegovich