python system_error ai_generated true

OSError: [Errno 98] 地址已被占用

OSError: [Errno 98] Address already in use

ID: python/starlette-uvicorn-port-in-use

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

generic

解决方案

  1. 95% 成功率
    lsof -i :8000 | awk 'NR>1 {print $2}' | xargs kill -9
  2. 92% 成功率
    uvicorn app:app --port 8001

无效尝试

常见但无效的做法:

  1. 85% 失败

    The old process keeps the port bound.

  2. 90% 失败

    Reload does not free the port; the parent still binds it.