Cleans up resources and closes connection
        :return:

def close(self):
        """
        Cleans up resources and closes connection
        :return:
        """
        if self._closed:
            return
        self._closed = True
        self.queue("close", None)
        if not self._flushed.wait(timeout=self._max_flush_time):
            raise ValueError("close timed out")