python
system_error
ai_generated
true
[Errno 98] 尝试绑定地址 ('0.0.0.0', 8000) 时出错:地址已被占用
[Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
ID: python/uvicorn-port-already-in-use
80%修复率
88%置信度
0证据数
2024-01-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.100+ | active | — | — | — |
| 0.110+ | active | — | — | — |
根因分析
先前的 uvicorn/gunicorn 工作进程仍占用端口,或另一服务绑定到 8000(reload 下 Ctrl+C 后常见)。
English
Previous uvicorn/gunicorn worker still holding the port, or another service bound to 8000 (common after Ctrl+C on reload).
解决方案
-
95% 成功率
lsof -i :8000 # then kill -9 <pid>
-
90% 成功率
uvicorn app:app --port 8001 # use a free port
无效尝试
常见但无效的做法:
-
70% 失败
Reload spawns more workers; port stays held.
-
80% 失败
Same port conflict.