From 22902048cd9b111643d440849a079369c1984c3f Mon Sep 17 00:00:00 2001 From: urec56 Date: Sat, 13 Jul 2024 14:39:09 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=20long=20polling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chat/websocket.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/chat/websocket.py b/app/chat/websocket.py index 6afcdfa..a3f76e2 100644 --- a/app/chat/websocket.py +++ b/app/chat/websocket.py @@ -1,4 +1,5 @@ import asyncio +from collections import defaultdict import websockets from fastapi import WebSocket, WebSocketDisconnect, Depends, HTTPException, status @@ -158,8 +159,8 @@ async def chat_ws( class PollingManager: def __init__(self): - self.waiters: dict[int, list[asyncio.Future]] = {} - self.messages: dict[int, list[dict]] = {} + self.waiters: dict[int, list[asyncio.Future]] = defaultdict(list) + self.messages: dict[int, list[dict]] = defaultdict(list) async def poll(self, chat_id: int): future = asyncio.Future()