From 81b76bddf7472a25c23fe07fbc703cd1257e00b4 Mon Sep 17 00:00:00 2001 From: Ro'e Katz Date: Thu, 29 Aug 2024 15:17:14 +0300 Subject: [PATCH] WebSocketsClientHandler: Fix no await for websocket.close --- fastapi_websocket_rpc/websocket_rpc_client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fastapi_websocket_rpc/websocket_rpc_client.py b/fastapi_websocket_rpc/websocket_rpc_client.py index 7b3079b..6a6d0d3 100644 --- a/fastapi_websocket_rpc/websocket_rpc_client.py +++ b/fastapi_websocket_rpc/websocket_rpc_client.py @@ -21,7 +21,7 @@ # Websocket-client optional module not installed. pass -class ProxyEnabledWebSocketClientHandler (SimpleWebSocket): +class ProxyEnabledWebSocketClientHandler(SimpleWebSocket): """ Handler that use https://websocket-client.readthedocs.io/en/latest module. This implementation supports HTTP proxy, though HTTP_PROXY and HTTPS_PROXY environment variable. @@ -93,7 +93,7 @@ async def recv(self): async def close(self, code: int = 1000): if self._websocket is not None: # Case opened, we have something to close. - self._websocket.close(code) + await asyncio.get_event_loop().run_in_executor(None, self._websocket.close, code) class WebSocketsClientHandler(SimpleWebSocket): """ @@ -154,7 +154,7 @@ async def recv(self): async def close(self, code: int = 1000): if self._websocket is not None: # Case opened, we have something to close. - self._websocket.close(code) + await self._websocket.close(code) def isNotInvalidStatusCode(value): return not isinstance(value, InvalidStatusCode)