python system_error ai_generated true

OSError: [Errno 98] Address already in use

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-01-09First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

Another process (often a previous uvicorn run) is already bound to the target port.

generic

中文

另一个进程(通常是之前的 uvicorn 运行)已绑定到目标端口。

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 85% fail

    The old process keeps the port bound.

  2. 90% fail

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