{
  "id": "python/asyncio-cannot-create-subprocess",
  "signature": "RuntimeError: Cannot create subprocess in event loop that is not running",
  "signature_zh": "运行时错误：无法在未运行的事件循环中创建子进程",
  "regex": "RuntimeError:\\ Cannot\\ create\\ subprocess\\ in\\ event\\ loop\\ that\\ is\\ not\\ running",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to create an asyncio subprocess (e.g., via asyncio.create_subprocess_exec) before the event loop is started or after it is stopped.",
  "root_cause_type": "generic",
  "root_cause_zh": "在事件循环启动前或停止后尝试创建 asyncio 子进程（例如通过 asyncio.create_subprocess_exec）。",
  "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using asyncio.get_event_loop() to get a loop and then calling run_until_complete",
      "why_fails": "get_event_loop() may return a closed loop; subprocess creation requires a running loop.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting the event loop policy to WindowsProactorEventLoopPolicy",
      "why_fails": "This only applies to Windows; the error is about loop state, not platform.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use asyncio.run() to automatically manage the event loop lifecycle",
      "success_rate": 0.95,
      "how": "async def main(): proc = await asyncio.create_subprocess_exec('cmd'); asyncio.run(main())",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ensure the loop is running before creating subprocess",
      "success_rate": 0.9,
      "how": "loop = asyncio.new_event_loop(); asyncio.set_event_loop(loop); loop.run_until_complete(create_subprocess())",
      "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.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}