# RuntimeError: async generator raised StopAsyncIteration

- **ID:** `python/starlette-async-iterator-exhausted`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Starlette 的异步生成器在迭代过程中被提前关闭或耗尽

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.10 | active | — | — |
| 3.11 | active | — | — |

## Workarounds

1. **确保异步生成器正确使用 async for 循环** (90% success)
   ```
   async for item in async_generator():
    process(item)
   ```
2. **在调用处捕获 StopAsyncIteration** (85% success)
   ```
   try:
    async for item in gen:
        ...
except StopAsyncIteration:
    pass
   ```

## Dead Ends

- **在生成器函数中添加 try-except 捕获 StopAsyncIteration** — 生成器内部不应捕获此异常，会导致状态混乱 (80% fail)
- **使用同步生成器替代** — 破坏了异步上下文，可能阻塞事件循环 (70% fail)
