Clean way to stop/close kite websocket connection

ksh
Hi,
Based on certain condition, i am shutting down my strategy threads and exiting main. At this point, kite websocket connection can also be closed.
When i do:
kws_list[ws_idx].stop()
at the end of my code,

i get this error:
  File "/home/kk/anaconda3/envs/kite/lib/python3.8/site-packages/twisted/internet/base.py", line 708, in stop
raise error.ReactorNotRunning("Can't stop reactor that isn't running.")
twisted.internet.error.ReactorNotRunning: Can't stop reactor that isn't running.
Please let me know a clean way to close these connections . I am using kws_l[ws_idx].connect(threaded=<b class="Bold"><b class="Bold">True</b></b>)
  • rakeshr
    You are trying to stop websocket multiple times, may be in a continuous loop. This thread explains more.
  • ksh
    Ok. I looked into the thread and tried to corelate with my code.

    I am running multiple websockets in threaded=True mode. This reactor not running error is only seen when I try to close all (multiple) websockets . The issue is NOT seen when i use single websocket.

    This is my code to stop connections. The issue is also not seen when i add time.sleep or add break (of course).




    So it appears to me that, closing 1 WS closes rest all connections ? is this true ?
  • rakeshr
    So it appears to me that, closing 1 WS closes rest all connections ? is this true ?
    Yes, if you close the main thread connection, all daemon threads created using threaded instances would be self-closed.
  • ksh
    Can u explain main thread connection ? all kws instances created for multiple websocket connections are independent right ?
  • rakeshr
    This thread explains more.
  • ksh
    Understood, if main thread stops, all other daemon threads also eventually dies. [general principal]
    1. Does it mean terminating kws connections explicitly is pointless, as it will die anyway as main exits ?
    2. In any case, if i have some post process to do and I want to close connections, closing any one kws will close all other connections ? (all kws are daemon threads)
  • rakeshr
    Does it mean terminating kws connections explicitly is pointless, as it will die anyway as main exits ?
    In any case, if i have some post process to do and I want to close connections, closing any one kws will close all other connections ? (all kws are daemon threads)
    Yes, exiting the main/closing the main websocket connection, would close all websocket connections with the kite websocket ticker.
Sign In or Register to comment.