Restarting a stopped socket thread

Rekha
I am able to stop the socket thread in python script from a telegram bot. But it fails to restart, even though I used the same command which I used to run it.
My kite_bot.py script is something like this:

import logging
from kiteconnect import KiteTicker

logging.basicConfig(level=logging.DEBUG)


def run():
kws = KiteTicker("your_api_key", "your_access_token")

def on_ticks(ws, ticks):
logging.debug("Ticks: {}".format(ticks))

def on_connect(ws, response):
ws.subscribe([738561, 5633])
ws.set_mode(ws.MODE_FULL, [738561])

def on_close(ws, code, reason):
ws.stop()

kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
kws.connect(threaded=True)

while True:
#Perform required data operation using tick data
def on_ticks(ws, ticks):
..........
helper_method(ticks)
.........

def helper_method(ticks):
.........
Perform computation here
CHECK STOP_KITE IF TRUE. IF TRUE, CALL on_close()
#Assign callback
kws.on_ticks=on_ticks

assign callback

bot_handler(run)



When I send run command from telegram app to my bot, it runs the run() and socket works fine. I have created a stop command which sets a variable stop_kite to True and I check this variable inside helper_method(). if it is found true, I call on_close()

It works fine up to this point but when I wish to restart it, it doesn't work. I get REACTOR NOT RESTARTABLE error.

How do I overcome this issue?


Sign In or Register to comment.