From 6ec23666b3615c3ac931b93af92f4ca92af88974 Mon Sep 17 00:00:00 2001 From: lifeimm100 <172345037+lifeimm100@users.noreply.github.com> Date: Tue, 8 Apr 2025 20:57:22 +0800 Subject: [PATCH] Add ping timer management in WebSocketManager This update introduces a ping_timer attribute to the _WebSocketManager class, ensuring that the ping timer is properly canceled when closing the websocket connection. --- pybit/_websocket_stream.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pybit/_websocket_stream.py b/pybit/_websocket_stream.py index 2ba0086..b006b7c 100644 --- a/pybit/_websocket_stream.py +++ b/pybit/_websocket_stream.py @@ -266,6 +266,7 @@ def _send_initial_ping(self): timer = threading.Timer( self.ping_interval, self._send_custom_ping ) + self.ping_timer = timer timer.start() @staticmethod @@ -288,7 +289,8 @@ def exit(self): """ Closes the websocket connection. """ - + if self.ping_timer: + self.ping_timer.cancel() self.ws.close() while self.ws.sock: continue