Python flask - builtins.ValueError: signal only works in main thread

Hi, I was trying to implement a web app using the ticker information. However I am using it as a just a function it all works fine but when I try to run the flask application, it throws the below error. Can anyone help me on how to handle the subscription of tick data in the web app. Appreciate the help.

handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
builtins.ValueError: signal only works in main thread
  • harshtock
    harshtock edited June 2020
    i tried the solutions mentioned in the stackoverflow thread, but none worked for me.
    An example would really help if you have. i even tried - it runs the app but doesn't load the webpage.

    @pssantosh did you solve this finally?
  • algo_trader_abhi
    Just see what Kite is doing internally,
    Kite allows to running ticker in threaded mode internally by using connect(threaded=True).

    If you look at connect code,

    if threaded:
    # Signals are not allowed in non main thread by twisted so suppress it.
    opts["installSignalHandlers"] = False
    self.websocket_thread = threading.Thread(, kwargs=opts)
    self.websocket_thread.daemon = True

    You can do the same!
Sign In or Register to comment.