RuntimeError: This event loop is already running, while connecting 3 websocket connections

Yamanrb12
I am trying to subscribe 8000 instruments on 3 websocket connection but getting this above error, what will be the cause can anyone suggest ?
  • rakeshr
    RuntimeError: This event loop is already running, while connecting 3 websocket connections
    Looks like, you are already running 3 WebSocket streams(maximum allowed connections). You need to stop all previous active connections and then initiate the new ones. Also, make sure you are not using any daemon/background process/threads in your current program to initiate new connections from the same.
  • Yamanrb12
    Yamanrb12 edited October 26
    Thank you @rakeshr for your reply, I am using python programming with Django framework,
    Whenever I run the server for the first time everything works fine, but for some reason if the server is restarted or if I restart it then I get this error.
    Where I created a class for the connection code and trying to create 3 instance of that class.
    like this

    with ThreadPoolExecutor(max_workers=3) as executor:
    try:
    executor.submit(kws1.connect, True)
    executor.submit(kws2.connect, True)
    executor.submit(kws3.connect, True)
    except:
    pass
  • rakeshr
    The old connection seems to be still active. Maybe this answer than help.
  • Yamanrb12
    Yamanrb12 edited November 2
    @rakeshr sir, I can try any of the solution in my code but I am really stucked where I think I can't do anything.
    Means I am getting the error just after I run kws.connect(threaded=True), where I commented two more connection instances.

    kws1.connect(threaded=True)
    print('kws connected.....................................')

    Here I attached the log file maybe this file will help.
  • rakeshr
    RuntimeError: This event loop is already running
    Go through the same mentioned thread above.
  • Yamanrb12
    Yamanrb12 edited November 2
    @rakeshr sir, Still I didn't get you, The thread you share I gone through that but where I should apply it when I didn't have any code to create async calls,
    are you saying that I have to call kws1.connect with await call ?
  • Yamanrb12
    Yamanrb12 edited November 2
    @rakeshr sir, is this can happening because of the use of celery for the periodic tasks ?
Sign In or Register to comment.