I am using the below code:
import paramiko
def runSshCmd(hostname, username, password, cmd, timeout=None):
client = paramiko.SSHClient()
I happen to come across this issue. But I kinda work around it by using "readline" instead "readlines".
For example:
client = paramiko.SSHClient()
client.connect(addr, port, username, password)
stdin, stdout, stderr = client.exec_command(cmd)
while True:
print(stdout.readline())
if stdout.channel.exit_status_ready():
break
So it will print every line immediately and no more hanging, also exit_status_ready() will make sure the loop breaks when stdout has stopped/exited.