ReactorNotRestartable Exception whenever kite.connect() is triggered

varuns
Hi

Whenever I host my python script in my staging environment, always the second time onwards I am getting this ReactorNotRestartable exception.
After hosting my code, first time, the code runs without any issue. but second time onwards, this below exception message is noticed and kite websocket is connected.

kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
kws.on_error = on_error
kws.connect()

Issue Source Line : kws.Connect()

def on_connect(ws, response):
print ("inside on_connect event")

The execution is not even going inside on_connect event and below exception is thrown. Needed your help.

Failure Exception: ReactorNotRestartable: Stack: File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 493, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 762, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper

Repeat: the issue is occuring only from second execution after the deployment. If I Deploy the script once again, then first time there is no issue. Each time during execution, i am creating a new Kite Session.

Thanks in Advance.
Varun
  • sujith
    You can refer to the FAQs here.
  • varuns
    Not helpful @sujith

    Please understand that, first time the ticker is working as expected. In my local environment is runs perfectly always. but in my VM, it runs only for 1st time. second time onwards I have this ReactorNotRestartable exception.
  • rakeshr
    but in my VM, it runs only for 1st time. second time onwards I have this ReactorNotRestartable exception
    Yeah, it might be something similar to this issue of the Anaconda environment. As, in those environments, twister can't be restarted. This GitHub issue explains more.
  • varuns
    I have to restart the environment to mitigate this issue. I have created a automated task to restart the function app before running, each time. Thanks for the prompt response.
This discussion has been closed.