ReactorNotRestartable()

mh82
I am having same issue as discussed here. https://kite.trade/forum/discussion/3118/websocket-streaming-error-reactornotrestartable


As mentioned in comments by Sujith, I tried to look for new code here:- https://github.com/zerodha/pykiteconnect/tree/kite3
But the webpage is giving 404 error.

How can I access new code example?



import logging
from kiteconnect import KiteTicker

logging.basicConfig(level=logging.DEBUG)

# Initialise
kws = KiteTicker(api_key, access_token)

def on_ticks(ws, ticks):
# Callback to receive ticks.
logging.debug("Ticks: {}".format(ticks))
pprint(ticks)

print("\n")

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

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

def on_close(ws, code, reason):
# On connection close stop the event loop.
# Reconnection will not happen after executing `ws.stop()`
ws.stop()

# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close

# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()

$$$$$$ ERROR$$$$$$

ReactorNotRestartable Traceback (most recent call last)
in
34 # Infinite loop on the main thread. Nothing after this will run.
35 # You have to use the pre-defined callbacks to manage subscriptions.
---> 36 kws.connect()

/opt/anaconda3/lib/python3.8/site-packages/kiteconnect/ticker.py in connect(self, threaded, disable_ssl_verification, proxy)
530 self.websocket_thread.start()
531 else:
--> 532 reactor.run(**opts)
533
534 def is_connected(self):

/opt/anaconda3/lib/python3.8/site-packages/twisted/internet/base.py in run(self, installSignalHandlers)
1315
1316 def run(self, installSignalHandlers: bool = True) -> None:
-> 1317 self.startRunning(installSignalHandlers=installSignalHandlers)
1318 self.mainLoop()
1319

/opt/anaconda3/lib/python3.8/site-packages/twisted/internet/base.py in startRunning(self, installSignalHandlers)
1297 """
1298 self._installSignalHandlers = installSignalHandlers
-> 1299 ReactorBase.startRunning(cast(ReactorBase, self))
1300
1301 def _reallyStartRunning(self) -> None:

/opt/anaconda3/lib/python3.8/site-packages/twisted/internet/base.py in startRunning(self)
841 raise error.ReactorAlreadyRunning()
842 if self._startedBefore:
--> 843 raise error.ReactorNotRestartable()
844 self._started = True
845 self._stopped = False

ReactorNotRestartable:
  • rakeshr
    It seems like an issue with your anaconda env. You can go through this thread to know more.
  • do2blehelix
    do2blehelix edited September 2021
    It works only on the anaconda session for the first time. If the connection is interrupted, the ReactorNotRestartable error comes back. Close your jupyter notebook session and restart. Or restart your kernel. It should work then.
  • mh82
    I am not able to resolve the issue.
    I tried restarting Jupiter lab twice or thrice

    I am very new to programming languages and also trading.

    I am not able to troubleshoot, looking for ready to deploy code.


    can anyone post the code or link of the code? or am I using the right code it is just the issue with anaconda?
  • rakeshr
    or am I using the right code it is just the issue with anaconda?
    Your WebSocket looks fine. You can check the Websocket example code here. It looks like, issue with your anaconda env.
  • mh82
    Oh ok.

    Thanks.
This discussion has been closed.