From 818597caa95dc38b524a249b2f9048a8e5f3c032 Mon Sep 17 00:00:00 2001 From: Shiven Mian Date: Tue, 13 Feb 2024 20:09:08 -0800 Subject: [PATCH] fix: don't output if websocket disconnected normally --- 01OS/01OS/server/server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/01OS/01OS/server/server.py b/01OS/01OS/server/server.py index 62ab6d8..3f38ab5 100644 --- a/01OS/01OS/server/server.py +++ b/01OS/01OS/server/server.py @@ -9,7 +9,7 @@ import traceback import re from fastapi import FastAPI from fastapi.responses import PlainTextResponse -from starlette.websockets import WebSocket +from starlette.websockets import WebSocket, WebSocketDisconnect from .stt.stt import stt_bytes from .tts.tts import tts from pathlib import Path @@ -99,6 +99,8 @@ async def websocket_endpoint(websocket: WebSocket): send_task = asyncio.create_task(send_messages(websocket)) try: await asyncio.gather(receive_task, send_task) + except WebSocketDisconnect: + pass except Exception as e: traceback.print_exc() logger.info(f"Connection lost. Error: {e}")