From f6d0cda6ce0e68eea982e6860a9c147a8013a8f1 Mon Sep 17 00:00:00 2001 From: nanoric Date: Fri, 15 Mar 2019 03:00:28 -0400 Subject: [PATCH] [Mod] WebSocketClient: remove useless lock. --- vnpy/api/websocket/websocket_client.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/vnpy/api/websocket/websocket_client.py b/vnpy/api/websocket/websocket_client.py index 2a1820a8..52f3eb01 100644 --- a/vnpy/api/websocket/websocket_client.py +++ b/vnpy/api/websocket/websocket_client.py @@ -107,13 +107,17 @@ class WebsocketClient(object): """ Send a text string to server. """ - return self._get_ws().send(text, opcode=websocket.ABNF.OPCODE_TEXT) + ws = self._ws + if ws: + ws.send(text, opcode=websocket.ABNF.OPCODE_TEXT) def _send_binary(self, data: bytes): """ Send bytes data to server. """ - return self._get_ws()._send_binary(data) + ws = self._ws + if ws: + ws._send_binary(data) def _reconnect(self): """""" @@ -143,11 +147,6 @@ class WebsocketClient(object): self._ws.close() self._ws = None - def _get_ws(self): - """""" - with self._ws_lock: - return self._ws - def _run(self): """ Keep running till stop is called. @@ -158,7 +157,7 @@ class WebsocketClient(object): # todo: onDisconnect while self._active: try: - ws = self._get_ws() + ws = self._ws if ws: text = ws.recv() @@ -215,7 +214,7 @@ class WebsocketClient(object): def _ping(self): """""" - ws = self._get_ws() + ws = self._ws if ws: ws.send("ping", websocket.ABNF.OPCODE_PING)