title: Paramiko: how to ensure data is received between commands
body: <p>I'm using Paramiko to issue a number of commands and collect results for further analysis.  Every once in a while the results from the first command are note fully returned in time and end up in the output for the second command.  </p>
  
  <p>I'm attempting to use recv_ready to account for this but it is not working so I assume I am doing something wrong.  Here's the relevant code:</p>
  
  <pre><code>pause = 1
  
  def issue_command(chan, pause, cmd):
      # send commands and return results
      chan.send(cmd + '\n')
      while not chan.recv_ready():
          time.sleep(pause)
      data = chan.recv(99999)
  
  ssh = paramiko.SSHClient()
  ssh.load_system_host_keys()
  ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  chan = ssh.connect(host, port=22, username=username, password=password, timeout=3,)
  
  resp1 = issue_command(chan, pause, cmd1)
  resp2 = issue_command(chan, pause, cmd2)
  </code></pre>
  
  <p>The output for these commands is relatively small (a few sentences). Increasing the pause would likely solve the problem but is not an ideal solution.</p>
  
  <p>Any suggestions or recommendations would be appreciated.  </p>