can't get commands on remote host after fixed amount of send commands

50 views Asked by At

I have a program with 2 threads. Every thread sends different commands to remote host and redirect output to file. Threads use different remote hosts. I've created a connection with pxssh and trying to send commands to remote hosts with 'sendline':

s = pxssh.pxssh()
try:
    s.login (ip, user, pswd)
except:
    logging.error("login: error")
    return

logging.debug("login: success")
s.sendline("ls / >> tmpfile.log")
s.prompt()

I can send fixed number of commands (about 500 commands on every host) and after that 'sendline' stops working. Connection is ok, but I can't get commands on remote hosts. It looks like some resources run out... what can it be?

1

There are 1 answers

0
Thomas K On BEST ANSWER

Reposting as an answer, since it solved the issue:

Are you reading in between each write? If the host is producing output and you're not reading it, sooner or later a buffer will fill up and it will block until there's room to write some more. Make sure that before each write, you read any data that's available in the terminal, even if you don't want to do anything with it.

If you really don't care about the output at all, you could create a thread that constantly reads in a loop, so that your main thread can skip reading altogether. If your code needs to do anything with any part of the output, though, don't do this.