# asyncio.TimeoutError: Task timed out after 30 seconds

- **ID:** `python/starlette-async-timeout-error`
- **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. **优化异步任务性能** (85% success)
   ```
   async def slow_task():
    await asyncio.sleep(10)  # 使用异步等待而非阻塞
   ```
2. **使用 asyncio.wait_for 设置合理超时** (90% success)
   ```
   try:
    result = await asyncio.wait_for(task(), timeout=30)
except asyncio.TimeoutError:
    return '超时', 408
   ```

## Dead Ends

- **移除超时设置而不优化代码** — 可能导致请求无限挂起 (80% fail)
- **增加超时时间到很大值** — 掩盖了性能问题 (60% fail)
