def _consume_stdout(self, chan, call_line_handler_func=False):
        """
        Try to consume stdout data from chan if it's receive ready.
        """

        out = bytearray()
        stdout = StringIO()

        if chan.recv_ready():
            data = chan.recv(self.CHUNK_SIZE)

            if six.PY3 and isinstance(data, six.text_type):
                data = data.encode("utf-8")

            out += data

            while data:
                ready = chan.recv_ready()

                if not ready:
                    break

                data = chan.recv(self.CHUNK_SIZE)

                if six.PY3 and isinstance(data, six.text_type):
                    data = data.encode("utf-8")

                out += data

        stdout.write(self._get_decoded_data(out))

        if self._handle_stdout_line_func and call_line_handler_func:
            data = strip_shell_chars(stdout.getvalue())
            lines = data.split("\n")
            lines = [line for line in lines if line]

            for line in lines:
                # Note: If this function performs network operating no sleep is
                # needed, otherwise if a long blocking operating is performed,
                # sleep is recommended to yield and prevent from busy looping
                self._handle_stdout_line_func(line=line + "\n")

            stdout.seek(0)

        return stdout

        Try to consume stdout data from chan if it's receive ready.
        
st2common/st2common/runners/paramiko_ssh.py