{
  "id": "python/no-running-event-loop",
  "signature": "RuntimeError: no running event loop",
  "signature_zh": "RuntimeError: 没有正在运行的事件循环",
  "regex": "RuntimeError:\\ no\\ running\\ event\\ loop",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "asyncio.get_running_loop() (or an API that calls it internally, like asyncio.create_task) was invoked from synchronous code outside any running loop.",
  "root_cause_type": "generic",
  "root_cause_zh": "在没有任何正在运行的循环的同步代码中调用了 asyncio.get_running_loop()（或内部调用它的 API，如 asyncio.create_task）。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Deprecated since 3.10 and emits DeprecationWarning; in 3.12 it still raises when no loop is set.",
      "fail_rate": 0.55,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Makes it worse — guarantees no loop is available.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Timing has nothing to do with loop presence.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Only call create_task/get_running_loop from inside a coroutine:\n\nasync def main():\n    asyncio.create_task(worker())\n\nasyncio.run(main())",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "From sync code that must schedule work, use asyncio.run_coroutine_threadsafe when you have a loop reference:\n\nfuture = asyncio.run_coroutine_threadsafe(coro(), loop)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "In Jupyter/IPython, use `await` directly in the cell, or call nest_asyncio.apply() once at the top of the notebook.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}