zerodha / pykiteconnect

The official Python client library for the Kite Connect trading APIs
MIT License
983 stars 470 forks source link

Allow an option for passing "installSignalHandlers" to reactor.run when threaded is set to False in the KiteTicker connect() function #41

Open h-vishal opened 6 years ago

h-vishal commented 6 years ago

We have a class that manages the ticker thread, with the switch to 3.0 we can't use the KiteTicker class directly because we are not running it in the main thread, and we can't use the threaded option in connect() because this creates a new thread in our ticker thread, which is suppose to block on the connect function.

This is the relevant snippet from the current version of the connect() function -

# Run in seperate thread of blocking
        opts = {}
        if threaded:
            # Signals are not allowed in non main thread by twisted so supress it.
            opts["installSignalHandlers"] = False
            self.websocket_thread = threading.Thread(target=reactor.run, kwargs=opts)
            self.websocket_thread.daemon = True
            self.websocket_thread.start()
        else:
            reactor.run(**opts)

Ideally we would like an input flag on the connect function to be able to set the "installSignalHandlers" in the else clause in the above snippet.

hemangjoshi37a commented 1 year ago

This is very nice idea. I hope this get PRed in the main repo. nice idea @h-vishal