ParallelSSH / parallel-ssh

Asynchronous parallel SSH client library.
https://parallel-ssh.org
GNU Lesser General Public License v2.1
1.2k stars 148 forks source link

stdout generator does not work correctly #365

Closed pbrezina closed 1 year ago

pbrezina commented 1 year ago

Calling list(output.stdout) returns the whole output correctly as expected:

    conn = pssh.clients.ssh.SSHClient(
        host='client.test',
        user='root',
        password='Secret123',
    )

    output = conn.run_command('echo -e "line1\nline2"')
    print('start')
    print(list(output.stdout))
    print('finished')

start
['line1', 'line2']
finished

However, if I want to return line by line by calling next(generator), then it only gets the first line, the second call raises StopIteration.

    conn = pssh.clients.ssh.SSHClient(
        host='client.test',
        user='root',
        password='Secret123',
    )

    output = conn.run_command('echo -e "line1\nline2"')
    print('start')
    print(next(output.stdout))
    print(next(output.stdout))
    print('finished')

        conn = pssh.clients.ssh.SSHClient(
            host='client.test',
            user='root',
            password='Secret123',
        )

        output = conn.run_command('echo -e "line1\nline2"')
        print('start')
        print(next(output.stdout))
>       print(next(output.stdout))
E       StopIteration

If I read first line and the call list, the result is empty - it does not get the rest.

    conn = pssh.clients.ssh.SSHClient(
        host='client.test',
        user='root',
        password='Secret123',
    )

    output = conn.run_command('echo -e "line1\nline2"')
    print('start')
    print(next(output.stdout))
    print('finished')
    conn.wait_finished(output)
    print(list(output.stdout))

start
line1
finished
[]

Reproducers are with libssh client, but it does not work with libssh2 as well.

pbrezina commented 1 year ago

Nevermind, this was my poor understanding of how generators work.