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?