-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Websockets RuntimeError "This event loop is already running" #1354
Comments
getting the same error, running in notebook this error only happens on junypter notebook runs fine as a python conda script can get it working with python-binance 1.0.15 but need to use 1.0.19 for the new futures endpoints trying to use 1.0.19 version to get new futures endpoints but getting the below error Exception in thread Thread-4: /Users/alex/opt/anaconda3/envs/trader/lib/python3.7/threading.py:960: RuntimeWarning: coroutine 'ThreadedApiManager.socket_listener' was never awaited code:
|
@sammchardy same here, happened in python 3.7, 3.8, 3.9,3.10. |
I get the same error, it's block me from upgrading. |
I would pay to have this fixed. |
i have same problem, but i fix it. Problem was in what i create twm instance in Thread-N, and try to use it in Thread-N+1
looks like you write some desktop app, so try watch what with threads there |
Please correct me if I am wrong, but as I see from the code - the So on creation of
And then when we call
Before the changes in commit a new event loop was created, what was perfectly logical, though And if, in some case, I want to create 2
And printing event loop object addresses of 2 separate objects of So I may misunderstand something, please correct me if I am wrong and there is no bug in it. |
I don't know what is your situation exactly, but the problem described by me above could be solved by replacing
|
When I'm trying to run a websocket, then in some time stop it, and run a new websocket, the following error occurs:
Exception in thread Thread-2:
Traceback (most recent call last):
File "D:\python\Python39\lib\threading.py", line 950, in _bootstrap_inner
self.run()
File "D:\python\Python39\lib\site-packages\binance\threaded_stream.py", line 59, in run
self._loop.run_until_complete(self.socket_listener())
File "D:\python\Python39\lib\asyncio\base_events.py", line 618, in run_until_complete
self._check_running()
File "D:\python\Python39\lib\asyncio\base_events.py", line 578, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
D:\python\Python39\lib\threading.py:952: RuntimeWarning: coroutine 'ThreadedApiManager.socket_listener' was never awaited
self._invoke_excepthook(self)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
This is a part of code which I use to run websocket:
twm = ThreadedWebsocketManager(self.main_window.api_key, self.main_window.api_secret)
twm.start()
current_candle_websocket = twm.start_kline_futures_socket(callback=self.handle_candle_message, symbol=self.symbol, interval=Client.KLINE_INTERVAL_5MINUTE)
This is a part of code which I use to stop websocket:
twm.stop_socket(current_candle_websocket)
twm.stop()
twm = ''
I use Python 3.9. The error didn't occur on python-binance 1.0.15, but since some API features are retired I can no longer use this version and updated python-binance to 1.0.19, and after that I am getting this error.
The text was updated successfully, but these errors were encountered: