[Python] Can't terminate a FastAPI app that is using websockets

Discussão em 'Python' iniciado por Stack, Junho 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have a FastAPI app with several HTTP routers and I added a simple websocket route like this:

    @router.websocket("/chat/{room_id}/")
    async def websocket_execute(
    websocket: WebSocket,
    ) -> None:
    await websocket.accept()
    try:
    while True:
    data = await websocket.receive_text()
    except WebSocketDisconnect:
    ...


    It is working, but if I have an active connection and try to stop the app using ctrl + C, this doesn't work. Only sigkill 9 works for stopping the app. For another HTTP router it is working properly.

    Continue reading...

Compartilhe esta Página