@convert_paramiko_errors
    def execute_command(self, cmd, pseudo_tty=False):
        def get_channel(ssh):
            channel = ssh.get_transport().open_session()
            if not channel:
                raise paramiko.SSHException("channel opening failed")
            return channel
        channel = self.get_ssh(get_channel)
        if not channel:
            raise errors.RemoteError("failed to open an SSH session to %s" % (
                    self.node.name))
        if pseudo_tty:
            channel.get_pty()

        channel.set_combine_stderr(True) # TODO: separate stdout/stderr?
        BS = 2**16
        rx_time = time.time()
        log_name = "%s (%s): %r" % (self.node.name, self.node.get("host"), cmd)
        next_warn = time.time() + self.warn_timeout
        next_ping = time.time() + self.ping_interval

        def available_output():
            """read all the output that is immediately available"""
            while channel.recv_ready():
                chunk = channel.recv(BS)
                yield rcontrol.STDOUT, chunk

        channel.exec_command(cmd)
        channel.shutdown_write()

        exit_code = None
        if epoll:
            poll = select.epoll()
            poll.register(channel.fileno(), select.EPOLLIN)
        else:
            poll = None

        try:
            while True:
                if (exit_code is None) and channel.exit_status_ready():
                    # process has finished executing, but there still may be
                    # output to read from stdout or stderr
                    exit_code = channel.recv_exit_status()

                # wait for input, note that the results are not used for anything
                if poll:
                    try:
                        poll.poll(timeout=1.0)  # just poll, not interested in the fileno
                    except __HOLE__ as ex:
                        if ex.errno != errno.EINTR:
                            raise
                        continue
                else:
                    select.select([channel], [], [], 1.0)

                for output in available_output():
                    rx_time = time.time()
                    next_warn = time.time() + self.warn_timeout
                    yield output

                if channel.closed and (exit_code is not None):
                    yield rcontrol.DONE, exit_code
                    break  # everything done!

                now = time.time()
                if now > (rx_time + self.terminate_timeout):
                    # no output in a long time, terminate connection
                    raise errors.RemoteError(
                        "%s: no output in %.1f seconds, terminating" % (
                            log_name, self.terminate_timeout))

                if now > next_warn:
                    elapsed_since = time.time() - rx_time
                    self.log.warning("%s: no output in %.1fs", log_name,
                                     elapsed_since)
                    next_warn = time.time() + self.warn_timeout

                if now > next_ping:
                    channel.transport.send_ignore()
                    next_ping = time.time() + self.ping_interval
        finally:
            if poll:
                poll.close()
dataset/ETHPy150Open ohmu/poni/poni/rcontrol_paramiko.py/ParamikoRemoteControl.execute_command