Skip to content

Client disconnect() blocks main thread for a long time #697

Description

@jsib0

Hello.

I am trying to disconnect the socket connection when I detect that the WiFi of my machine is disconnected. However, when I perform a disconnect() when the WiFi is disconnected, I receive the following logs below then the main thread stops right after. It takes time for the main thread to revive... Any directions to move forward is highly appreciated. Thank you in advance.

Client logs:

Sending packet MESSAGE data 1/socket
Sending packet MESSAGE data 1
Sending packet CLOSE data None
Exiting Write loop task
Engine.IO Connection dropped
Exiting ping task

Code to disconnect

    def attempt_connection(self):
        logger.info("Attempting connection")
        if self.net.has_internet:
            if self.client.connected:
                return True
            try:
                self.client.connect()
            except ConnectionError:
                return False
        elif self.client.connected:
            try:
                self.client.disconnect()
            except:
                logger.info("except")

        return False

## client class
Class Client:
    def disconnect(self):
        self.sio_client.disconnect()
        self.sio_client.wait()
        return True

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions