Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Websockets RuntimeError "This event loop is already running"

Aperta
#1,354 7 commenti 7 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
api, networking

Direzione di ricerca

Start in binance/threaded_stream.py, especially ThreadedApiManager.run and socket_listener, and trace how start(), stop_socket(), and stop() manage the event loop. Reproduce the restart sequence with Python 3.9 and python-binance 1.0.19; done means restarting a websocket no longer raises RuntimeError or leaves socket_listener unawaited.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
7.2k
Fork
2.3k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sammchardy/python-binance

Tutte le issue di sammchardy/python-binance

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.