twisted.internet.error.ReactorNotRestartable

Rekha
How shall I restart the websocket as and when I wish through my logic. At some point in my logic and use kws.stop() command to close the websocket thread. At some other point in my logic, I need to call the function which creates websocket again and use the ticks. but when I do that, it throws this error:
twisted.internet.error.ReactorNotRestartable

what does it mean and how I solve this issue?
Thanks in advance
  • rakeshr
    twisted.internet.error.ReactorNotRestartable
    This error is thrown by the Twisted when you are trying to re-run a reactor that was stopped. You can not use the same process to re-run the reactor, once it's stopped by the reactor.stop() event. This same event is used in the on_close method as well.
  • Rekha
    Thanks Rakeshr, I get this much now. Facing new challenge now.

    Even if I use close() function like kws.close() and later recall the function that creates the websocket and run the thread, it fails to create the websocket. How do I close and restart the websocket as and when required by the logic that I am writing?
  • rakeshr
    How do I close and restart the websocket as and when required by the logic that I am writing?
    You can't. You will have to spun-up the whole process again to initiate a websocket connection if it's forced closed/stopped from your end.
  • Rekha
    oh okay. so the only solution left is to use multiprocessing. create a process for websocket. use it. close it when I want. and restart it. sounds plausible?
  • Rekha
    or, don't use the close() or stop() function at all. check the websocket through kws.is_connected(). if it is False, return from the thread.
  • rakeshr
    Yes, you can keep the websocket connection alive and know the current status using is_connected method.
  • Rekha
    what happens to the websocket connection when the token expires due to the change of date? will it restart working if I update the access_token through another function?
  • rakeshr
    what happens to the websocket connection when the token expires due to the change of date?
    You can use subscribe method to subscribe to the new list of tokens.
  • Rekha
    I reframe the question: what happens to websocket connection when the access token expires? and when does access token expires? Does the expiry of access token has no effect on websocket?
Sign In or Register to comment.