{
  "id": "python/asyncio-loop-already-running-nested",
  "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": "loop.run_until_complete() was called from inside a coroutine that is already executing on the same loop, causing nested loop execution which asyncio forbids.",
  "root_cause_type": "generic",
  "root_cause_zh": "在已运行于同一循环的协程内部调用了 loop.run_until_complete()，导致 asyncio 禁止的嵌套循环执行。",
  "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": "get_event_loop returns the running loop; run_until_complete still raises.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The loop is still running; a yield point does not allow re-entrant run_until_complete.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "async def outer():\n    # WRONG: loop.run_until_complete(inner())\n    await inner()  # correct",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "result = await asyncio.to_thread(sync_blocking_fn, arg1, arg2)",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}