Keyboard interrupt not working

charuvindatre
charuvindatre edited October 2016 in Python client
I am using websocket client to store data however the keyboard interrupt is not working. I end up killing the session all the time, making it inefficient for me to logout automatically. Can anyone advise on any working alternate method? My motive is simple, to interrupt the live stream whenever I want and subsequently invalidate access token.

try:
while(True):
time.sleep(0.1)
kws.reconnect()
kws.connect()
except KeyboardInterrupt:
kite.invalidate_token()
print("Logged out successfully")
Tagged:
  • Kailash
    @charuvindatre Oh wow, why are you calling connect() and reconnect() in a loop? kws.connect() has an infinite loop within itself.
  • charuvindatre
    @Kailash I haven't seen the source code so I wasn't sure. I observed that in case my internet stops working, the streams usually stopped so by reconnecting I was able to stream seamlessly when my internet is up again.
  • Kailash
    You should do that every few seconds then. An infinite while loop like that is going to stress the CPU.
Sign In or Register to comment.