python system_error ai_generated true

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

OSError: [Errno 98] Address already in use

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

其他格式: JSON · Markdown 中文 · English
80%修复率
89%置信度
0证据数
2024-02-22首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

另一个进程(通常是之前的 uvicorn 重载进程)已占用该主机/端口。

English

Another process (often a previous uvicorn reloader) is already bound to the host/port.

generic

解决方案

  1. 92% 成功率
    Find and kill the holder:
    lsof -i :8000
    kill -9 <PID>
  2. 90% 成功率
    Run on a different port:
    uvicorn app:app --port 8001

无效尝试

常见但无效的做法:

  1. 85% 失败

    Reload doesn't free the port; it spawns another process that fails to bind.

  2. 90% 失败

    More workers compete for the same port and worsen the conflict.