MCPcopy Create free account
hub / github.com/dbunt1tled/python-fast-api / disconnect

Method disconnect

src/core/web_socket/ws_manager.py:30–40  ·  view source on GitHub ↗
(self, user_id: str, websocket: WebSocket)

Source from the content-addressed store, hash-verified

28 self.log.info(f"🍏 WebSocket connected: {user_id} (total {len(self._connections.get(user_id, []))})")
29
30 async def disconnect(self, user_id: str, websocket: WebSocket) -> None:
31 async with self._lock:
32 conns = self._connections.get(user_id, [])
33 conns = [c for c in conns if c[0] is not websocket]
34 if not conns:
35 self._connections.pop(user_id, None)
36 try:
37 await websocket.close(code=status.WS_1000_NORMAL_CLOSURE)
38 except Exception as e:
39 self.log.warning(f"🫜 WebSocket failed to close to {user_id}: {e}")
40 self.log.info(f"🍎 WebSocket disconnected: {user_id}")
41
42 async def send_to_user(self, user_id: str, data: dict[str, Any], websocket: WebSocket | None = None) -> int:
43 conns = self._connections.get(user_id, [])

Callers 2

_safe_sendMethod · 0.95
remove_connectionMethod · 0.80

Calls 3

warningMethod · 0.80
infoMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected