python
system_error
ai_generated
true
OSError: [Errno 98] 地址已被占用
OSError: [Errno 98] Address already in use
ID: python/starlette-uvicorn-port-in-use
80%修复率
88%置信度
0证据数
2024-01-09首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
另一个进程(通常是之前的 uvicorn 运行)已绑定到目标端口。
English
Another process (often a previous uvicorn run) is already bound to the target port.
解决方案
-
95% 成功率
lsof -i :8000 | awk 'NR>1 {print $2}' | xargs kill -9 -
92% 成功率
uvicorn app:app --port 8001
无效尝试
常见但无效的做法:
-
85% 失败
The old process keeps the port bound.
-
90% 失败
Reload does not free the port; the parent still binds it.