{
  "id": "python/asyncio-event-loop-already-running",
  "signature": "RuntimeError: This event loop is already running",
  "signature_zh": "RuntimeError: 此事件循环已在运行",
  "regex": "RuntimeError:\\ This\\ event\\ loop\\ is\\ already\\ running",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling asyncio.run() or loop.run_until_complete() from within an already-running event loop, e.g. inside a Jupyter notebook, an async function, or a framework that already owns the loop.",
  "root_cause_type": "generic",
  "root_cause_zh": "在已经运行的事件循环内部调用了 asyncio.run() 或 loop.run_until_complete()，例如在 Jupyter notebook、异步函数或已持有循环的框架中。",
  "versions": [
    {
      "version": "3.8+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Stopping the loop corrupts the outer framework's scheduling and causes pending tasks to hang.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Creates a nested loop that cannot await futures belonging to the outer loop; raises 'attached to a different loop'.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "import nest_asyncio\nnest_asyncio.apply()\nasyncio.run(main())",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "async def outer():\n    await main()  # instead of asyncio.run(main())",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}