def disconnect(self):
        """ Disconnect from the websocket and pause the process
            till we reconnect
        """
        logger.debug("Disconnecting")

        # Close off the websocket
        if self.ws:
            try:
                if self._state == STATE_CONNECTED:
                    self.handle_leave()
                    self.send_message(GOODBYE(
                          details={},
                          reason="wamp.error.system_shutdown"
                        ))
                logger.debug("Closing Websocket")
                try:
                    self.ws.close()
                except Exception as ex:
                    logger.debug("Could not close websocket connection because: {}".format(ex))
            except Exception as ex:
                logger.debug("Could not send Goodbye message because {}".format(ex))
                pass # FIXME: Maybe do better handling here
            self.ws = None

        # Cleanup the state variables. By settings this
        # we're going to be telling the main loop to stop
        # trying to read from a websocket and await a notice
        # of restart via a threading.Condition object
        self._state = STATE_DISCONNECTED

        # Send a message to all queues that we have disconnected
        # Without this, any requests that are awaiting a response
        # will block until timeout needlessly
        for request_id, request_queue in self._requests_pending.items():
            request_queue.put(GOODBYE(
                          details={},
                          reason="wamp.error.system_shutdown"
                        ))
        self._requests_pending = {}
        self.handle_disconnect()
def disconnect ( self ) : logger . debug ( "Disconnecting" ) if self . ws : try : if self . _state == STATE_CONNECTED : self . handle_leave ( ) self . send_message ( GOODBYE ( details = { } , reason = "wamp.error.system_shutdown" ) ) logger . debug ( "Closing Websocket" ) try : self . ws . close ( ) except Exception as ex : logger . debug ( "Could not close websocket connection because: {}" . format ( ex ) ) except Exception as ex : logger . debug ( "Could not send Goodbye message because {}" . format ( ex ) ) pass self . ws = None self . _state = STATE_DISCONNECTED for request_id , request_queue in self . _requests_pending . items ( ) : request_queue . put ( GOODBYE ( details = { } , reason = "wamp.error.system_shutdown" ) ) self . _requests_pending = { } self . handle_disconnect ( )
Disconnect from the websocket and pause the process
            till we reconnect