python async_error ai_generated true

RuntimeWarning: coroutine 'func' was never awaited

ID: python/runtimeerror-coroutine-never-awaited

Also available as: JSON · Markdown
95%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
311 active

Root Cause

Called async function without await. Returns a coroutine object, doesn't execute.

generic

Workarounds

  1. 98% success Add await keyword: result = await async_function()
    result = await async_function()

    Sources: https://docs.python.org/3/library/asyncio-task.html#coroutines

  2. 90% success If calling from sync code, use asyncio.run(async_function())
    async_function(

    Sources: https://docs.python.org/3/library/asyncio-runner.html#asyncio.run

Dead Ends

Common approaches that don't work:

  1. Wrap in asyncio.ensure_future() 55% fail

    Works but less readable — just use await

Error Chain

Preceded by:
Frequently confused with: