Paramiko ssh die/hang with big output

If the ls -R prints lots of error output (what is likely if the current user is not root => does not have access to all folders), your code deadlocks eventually.

It’s because, the output buffer of the error stream eventually fills, so the ls stops working, waiting for you to read the stream (empty the buffer).

While you wait for the regular output stream to finish, what it never does, as the ls waits for you to read the error stream, what you never do.

You have to read both streams in parallel (see Run multiple commands in different SSH servers in parallel using Python Paramiko).

Or even easier, use the Channel.set_combine_stderr to merge both streams to one.

Leave a Comment