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

其他格式: JSON · Markdown 中文 · English
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).

generic

解决方案

  1. 95% 成功率
    lsof -i :8000  # then kill -9 <pid>
  2. 90% 成功率
    uvicorn app:app --port 8001  # use a free port

无效尝试

常见但无效的做法:

  1. 70% 失败

    Reload spawns more workers; port stays held.

  2. 80% 失败

    Same port conflict.