{
  "id": "python/starlette-async-iterator-exhausted",
  "signature": "RuntimeError: async generator raised StopAsyncIteration",
  "signature_zh": "运行时错误：异步生成器引发了 StopAsyncIteration",
  "regex": "RuntimeError:\\ async\\ generator\\ raised\\ StopAsyncIteration",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Starlette 的异步生成器在迭代过程中被提前关闭或耗尽",
  "root_cause_type": "generic",
  "root_cause_zh": "Starlette 的异步生成器在迭代过程中被提前关闭或耗尽",
  "versions": [
    {
      "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": "在生成器函数中添加 try-except 捕获 StopAsyncIteration",
      "why_fails": "生成器内部不应捕获此异常，会导致状态混乱",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "使用同步生成器替代",
      "why_fails": "破坏了异步上下文，可能阻塞事件循环",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "确保异步生成器正确使用 async for 循环",
      "success_rate": 0.9,
      "how": "async for item in async_generator():\n    process(item)",
      "condition": "",
      "sources": []
    },
    {
      "action": "在调用处捕获 StopAsyncIteration",
      "success_rate": 0.85,
      "how": "try:\n    async for item in gen:\n        ...\nexcept StopAsyncIteration:\n    pass",
      "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.81,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}