{
  "id": "python/asyncio-cannot-reenter-running-loop",
  "signature": "RuntimeError: Cannot run the event loop while another loop is running",
  "signature_zh": "RuntimeError: 在另一个循环运行时无法运行事件循环",
  "regex": "RuntimeError:\\ Cannot\\ run\\ the\\ event\\ loop\\ while\\ another\\ loop\\ is\\ running",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling loop.run_until_complete() or asyncio.run() from within a coroutine that is already executing on a running loop.",
  "root_cause_type": "generic",
  "root_cause_zh": "在已在运行循环上执行的协程中调用 loop.run_until_complete() 或 asyncio.run()。",
  "versions": [
    {
      "version": "3.7+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "asyncio.run() refuses when a loop is already running and raises the same error.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Same restriction: you cannot nest loop runners on the same thread.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "async def outer():\n    result = await inner_coro()  # no nested loop",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.82,
      "how": "import asyncio, concurrent.futures\nloop = asyncio.get_running_loop()\nwith concurrent.futures.ThreadPoolExecutor() as pool:\n    result = await loop.run_in_executor(pool, lambda: asyncio.run(inner_coro()))",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}