Websockets: Infinite loop in main thread

batbark
batbark edited December 2017 in Python client
hello,
In the below code what does it mean by "Infinite loop on the main thread. Nothing after this will run"

I want to write the data to mysql table every 10 seconds, so I am trying to put a timer inside,
I want to know what part of the code is in infinite loop?
from kiteconnect import WebSocket

# Initialise.
kws = WebSocket("your_api_key", "your_public_token", "logged_in_user_id")

# Callback for tick reception.
def on_tick(tick, ws):
print tick

# Callback for successful connection.
def on_connect(ws):
# Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
ws.subscribe([738561, 5633])

# Set RELIANCE to tick in `full` mode.
ws.set_mode(ws.MODE_FULL, [738561])

# Assign the callbacks.
kws.on_tick = on_tick
kws.on_connect = on_connect

kws.enable_reconnect(reconnect_interval=5, reconnect_tries=50)
# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()
  • prat
    @batbark The main script run in an infinite loop. you have to do your calculations and ingesting to database etc
    using the mentioned callbacks (on_tick).
    So the ontick definition will handle that part
Sign In or Register to comment.