LUCIT-Systems-and-Development / unicorn-binance-websocket-api

A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.
https://unicorn-binance-websocket-api.docs.lucit.tech/
Other
677 stars 166 forks source link

Can't cancel stream #303

Closed dima-dmytruk23 closed 1 year ago

dima-dmytruk23 commented 1 year ago

Version of this library.

unicorn_binance_websocket_api==1.40.7

Solution to Issue cannot be found in the documentation or other Issues and also occurs in the latest version of this library.

Hardware?

Local server/workstation

Operating System?

Linux

Python version?

Python3.9

Installed packages

No response

Logging output

2023-02-09 13:12:11 265.15865325927734 | INFO | 1 | 140580945057536 | manager | manager.py:3442 | BinanceWebSocketApiManager.stop_manager_with_all_streams() - Stopping unicorn_binance_websocket_api_manager 1.40.7 ...
2023-02-09 13:12:11 272.07469940185547 | INFO | 1 | 140580945057536 | manager | manager.py:3546 | BinanceWebSocketApiManager.stream_is_stopping(3b8a256f4a9c-9c3b-7bbc-303b-1d643132)
2023-02-09 13:12:11 272.244930267334 | INFO | 1 | 140580945057536 | manager | manager.py:2745 | BinanceWebSocketApiManager.kill_stream(3b8a256f4a9c-9c3b-7bbc-303b-1d643132)
e=KeyError('3b8a256f4a9c-9c3b-7bbc-303b-1d643132')
2023-02-09 13:12:12 274.395227432251 | INFO | 1 | 140580945057536 | manager | manager.py:1511 | BinanceWebSocketApiManager.delete_stream_from_stream_list(3b8a256f4a9c-9c3b-7bbc-303b-1d643132)

Processing method?

stream_buffer

Used endpoint?

binance.com-futures

Issue

Hello. I created a flow ['kline_1h'], ['btcusdt']

After a while I try to cancel this stream

ubwa.stop_manager_with_all_streams()
ubwa.clear_stream_buffer()
for stream in ubwa_list:
    logger.info(f"{stream=}")
    try:
        ubwa.kill_stream(stream_id=stream)
    except Exception as e:
        print(f"{e=}")

        time.sleep(1)
        ubwa.delete_stream_from_stream_list(stream)
    try:
        if ubwa.wait_till_stream_has_stopped(stream):
            ubwa.delete_stream_from_stream_list(stream_id=stream)
    except Exception as e:
        print(f"{e=}")
        pass
ubwa.join()

But I see the data keeps coming...

dima-dmytruk23 commented 1 year ago

Perhaps this is due to the fact that I created the stream in a child process, and I'm trying to kill it in the parent?

alkhachatryan commented 1 year ago

@dima-dmytruk23 what was the issue? And how did you resolve it? I have similar problem, I try to kill the stream in a handler function. But looks like it cannot do that

dima-dmytruk23 commented 1 year ago

@dima-dmytruk23в чем проблема? И как вы это решили? У меня похожая проблема, я пытаюсь убить поток в функции-обработчике. Но похоже, что он не может этого сделать

The problem was that I created streams in child processes (multiprocessing), and tried to close them in the parent. I ended up using multiprocessing.Queue to keep the objects in sync.