# asyncpg.exceptions.InterfaceError: 无法执行操作：另一个操作正在进行中

- **ID:** `python/asyncpg-cannot-perform-operation-another-operation-in-progress`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

两个协程并发使用了同一个 asyncpg 连接。asyncpg 连接不是并发安全的，同一时间只能由一个协程使用。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8+ | active | — | — |
| 3.9+ | active | — | — |
| 3.10+ | active | — | — |
| 3.11+ | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   pool = await asyncpg.create_pool(dsn, min_size=1, max_size=10)
async with pool.acquire() as conn:
    await conn.fetch('SELECT 1')
   ```
2. **** (90% 成功率)
   ```
   lock = asyncio.Lock()
async with lock:
    await conn.fetch(query)
   ```

## 无效尝试

- **** — Does not serialize access; race still occurs under load. (80% 失败率)
- **** — Retries can still collide with the same concurrent coroutine and corrupt protocol state. (75% 失败率)
