def run(self):
        """ Start polling the socket. """
        # pylint: disable=too-many-branches
        self.heartbeat_controller.reset()
        self._force_recon = False
        while not self.stop.is_set():

            try:
                if not self._check_connection():
                    continue
            except ChromecastConnectionError:
                break

            # poll the socket
            can_read, _, _ = select.select([self.socket], [], [], POLL_TIME)

            # read messages from chromecast
            message = data = None
            if can_read in self.socket and not self._force_recon:
                try:
                    message = self._read_message()
                except InterruptLoop as exc:
                    if self.stop.is_set():
                        self.logger.info(
                            "Stopped while reading message, disconnecting.")
                        break
                    else:
                        self.logger.exception(
                            "Interruption caught without being stopped %s",
                            exc)
                        break
                except ssl.SSLError as exc:
                    if exc.errno == ssl.SSL_ERROR_EOF:
                        if self.stop.is_set():
                            break
                    raise
                except socket.error:
                    self._force_recon = True
                    self.logger.info('Error reading from socket.')
                else:
                    data = _json_from_message(message)
            if not message:
                continue

            # If we are stopped after receiving a message we skip the message
            # and tear down the connection
            if self.stop.is_set():
                break

            # See if any handlers will accept this message
            self._route_message(message, data)

            if REQUEST_ID in data:
                callback = self._request_callbacks.pop(data[REQUEST_ID], None)
                if callback is not None:
                    event = callback['event']
                    callback['response'] = data

                    event.set()

        # Clean up
        self._cleanup()
dataset/ETHPy150Open balloob/pychromecast/pychromecast/socket_client.py/SocketClient.run/swapped operands of `in`