if i lose my internet connection how to manage websocket connection

import time
import logging
from binance.lib.utils import config_logging
from binance.websocket.spot.websocket_client import SpotWebsocketClient as Client
config_logging(logging, logging.DEBUG)

def message_handler(message):
print(message)

my_client = Client()
my_client.start()

my_client.kline(symbol=“btcusdt”, id=1, interval=“1m”, callback=message_handler)

time.sleep(5)

my_client.kline(symbol=“bnbusdt”, id=2, interval=“3m”, callback=message_handler)

time.sleep(10)

logging.debug(“closing ws connection”)
my_client.stop()


I’m use official python binance-connector.

I’m get kline data with websocket.
Sometimes, I lost my internet connection.
I’m checking internet connection every 10 second in another thread .
if i lost my internet connection I’m closed websocket with myclient.close() method.
if the connection came back I’m open websocket with my_client.kline() method.

But this way cause memory leak. Memory is constantly growing in system.

Where am i doing wrong?

Can someone tell me how to manage websocket connection if I’m lost my internet connection?

When the internet connection is lost, the library still tries to connect for a default of 10 times. During this time you don’t have to call the .stop().

If it exceeds the 10x and the connection is stablished, the use of .stop() should remove all the connections .

So try to troubleshoot and see what’s the exact reason for the memory leak based on your running processes, your local code and the library’s websocket code.

Thanks for your answer. I will try then turn back