Fixed event loop creation issue in threaded_stream.py file
Fixed event loop creation issue in threaded_stream.py file by simple checking if the loop is already created or not. If is not created - create a new one, otherwise get current one
@sammchardy this is very simple fix to a very critical bug which stopped a lof of projects and blocked them. At least one we have here: https://github.com/conor19w/Binance-Futures-Trading-Bot/issues/61
Merge it as soon as possible. Thanks.
Thanks @alkhachatryan
you 2
@alkhachatryan Hello, I'm afraid your fix broke something because with it, the code just hangs (using python3.12 now)
Example
def main():
symbol = "BNBBTC"
twm = ThreadedWebsocketManager(api_key=api_key, api_secret=api_secret)
# start is required to initialise its internal loop
twm.start()
def handle_socket_message(msg):
print(msg)
twm.start_kline_socket(callback=handle_socket_message, symbol=symbol)
# multiple sockets can be started
twm.start_depth_socket(callback=handle_socket_message, symbol=symbol)
streams = ["bnbbtc@miniTicker", "bnbbtc@bookTicker"]
twm.start_multiplex_socket(callback=handle_socket_message, streams=streams)
twm.join()
main()
@carlosmiei hey. Strange, I didn't get that issue in ubuntu(intel), raspbian(amd) and VM ubuntu on AWS. If you sure it's my fix, please provide more info, if needed we can have a call to find out the problem
@alkhachatryan Can you please run the snippet above and report back the result? Right now have multiple reports (check the linked PR) that adding asyncio.get_event_loop() if asyncio.get_event_loop().is_running() else asyncio.new_event_loop() freezes the code execution.
@alkhachatryan Also I think that asyncio.get_event_loop().is_running() is not the same thing as there's no event loop in the thread. 🤔
Hi @alkhachatryan , do you have an example that caused an issue with this code?
@pcriadoperez https://github.com/conor19w/Binance-Futures-Trading-Bot/issues/61 here you can see the backtrace
@pcriadoperez and @carlosmiei let's continue the discussion in PR https://github.com/sammchardy/python-binance/pull/1449