python runtime_error ai_generated true

RuntimeWarning: coroutine 'fetch' was never awaited

ID: python/asyncio-coroutine-never-awaited

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-04-08First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8+ active
3.9+ active
3.10+ active
3.11+ active
3.12+ active

Root Cause

A coroutine function was called but the returned coroutine object was not awaited or scheduled, so the body never executed.

generic

中文

调用了协程函数但返回的协程对象既未 await 也未调度,导致函数体从未执行。

Workarounds

  1. 97% success
    await fetch(url)
    # or
    asyncio.create_task(fetch(url))
  2. 85% success
    PYTHONASYNCIODEBUG=1 python app.py
    # or in code:
    loop = asyncio.get_running_loop()
    loop.set_debug(True)

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Hides the warning but the coroutine still never runs; business logic silently missing.

  2. 85% fail

    Both calls produce unawaited coroutine objects; neither executes.