python system_error ai_generated true

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

OSError: [Errno 98] Address already in use

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

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

版本兼容性

版本状态引入弃用备注
0.30+ active — — —

根因分析

之前的服务器进程仍占用该端口(如 uvicorn --reload 遗留僵尸进程,或其他应用占用 8000)。

English

A previous server process is still bound to the port (e.g., uvicorn --reload left a zombie, or another app holds 8000).

generic

解决方案

  1. 97% 成功率
    lsof -i :8000 | awk 'NR>1{print $2}' | xargs kill -9
    # Windows:
    netstat -ano | findstr :8000
  2. 95% 成功率
    uvicorn main:app --port 8001

无效尝试

常见但无效的做法:

  1. 60% 失败

    Zombie process survives terminal close.

  2. 90% 失败

    uvicorn already sets it; a live listener still blocks.