{
  "id": "python/asyncio-event-loop-closed",
  "signature": "RuntimeError: Event loop is closed",
  "signature_zh": "运行时错误：事件循环已关闭",
  "regex": "RuntimeError:\\ Event\\ loop\\ is\\ closed",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to use an asyncio event loop after it has been explicitly closed, often due to calling loop.close() prematurely or reusing a loop after shutdown.",
  "root_cause_type": "generic",
  "root_cause_zh": "在事件循环已被显式关闭后尝试使用它，通常是因为过早调用 loop.close() 或在关闭后重用循环。",
  "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Recreating the loop with asyncio.new_event_loop() without setting it as current",
      "why_fails": "The new loop is not set as the current loop, so asyncio.get_event_loop() still returns a closed loop.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignoring the error and continuing execution",
      "why_fails": "The closed loop cannot process coroutines, leading to hangs or crashes later.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using loop.run_forever() after loop.close()",
      "why_fails": "A closed loop cannot be restarted; run_forever() raises RuntimeError.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use asyncio.run() for top-level entry point to avoid manual loop management",
      "success_rate": 0.95,
      "how": "async def main(): await some_coroutine(); asyncio.run(main())",
      "condition": "",
      "sources": []
    },
    {
      "action": "Check if loop is closed before using it, and create a new one if needed",
      "success_rate": 0.85,
      "how": "if loop.is_closed(): loop = asyncio.new_event_loop(); asyncio.set_event_loop(loop)",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}