original_docstring: Sends a command and returns stdout, stderr and exitcode
docstring: Sends a command and returns stdout, stderr and exitcode
docstring_tokens: Sends a command and returns stdout stderr and exitcode
code: def send_command(self,
                       command,
                       exec_timeout=3000,
                       read_chunk_timeout=500,
                       wait_result=False):
          """Sends a command and returns stdout, stderr and exitcode"""
  
          # Check if connection is made previously
          if self._client is not None:
  
              if self._login_shell:
                  cmd = "bash -l -c {}".format(shlex_quote(command))
              else:
                  cmd = command
              # there is one channel per command
              retries = 3
              while True:
                  try:
                      stdin, stdout, stderr = self._client.exec_command(
                          cmd,
                          timeout=exec_timeout)
                  except (SSHException, socket.error) as se:
                      if retries > 0:
                          retries -= 1
                          logging.getLogger("paramiko").warning("Retrying SSH connection: " + str(se))
                          continue
                      else:
                          raise se
                  break
  
              if wait_result:
                  # get the shared channel for stdout/stderr/stdin
                  channel = stdout.channel
  
                  # we do not need stdin
                  stdin.close()
                  # indicate that we're not going to write to that channel
                  channel.shutdown_write()
  
                  # read stdout/stderr in order to prevent read block hangs
                  stdout_chunks = []
                  stdout_chunks.append(stdout.channel.recv(
                      len(stdout.channel.in_buffer)))
                  stdout_chunks.append(stderr.channel.recv(
                      len(stderr.channel.in_buffer)))
                  # chunked read to prevent stalls
                  while (not channel.closed
                         or channel.recv_ready()
                         or channel.recv_stderr_ready()):
                      # Stop if channel was closed prematurely,
                      # and there is no data in the buffers.
                      got_chunk = False
                      readq, _, _ = select.select([stdout.channel],
                                                  [],
                                                  [],
                                                  read_chunk_timeout)
                      for c in readq:
                          if c.recv_ready():
                              stdout_chunks.append(stdout.channel.recv(
                                  len(c.in_buffer)))
                              got_chunk = True
                          if c.recv_stderr_ready():
                              # make sure to read stderr to prevent stall
                              stdout_chunks.append(stderr.channel.recv_stderr(len(c.in_stderr_buffer)))
                              got_chunk = True
                      """
                      1) make sure that there are at least 2 cycles with no data
                          in the input buffers in order to not exit too early
                          (i.e. cat on a >200k file).
                      2) if no data arrived in the last loop, check if we already
                          received the exit code
                      3) check if input buffers are empty
                      4) exit the loop
                      """
                      if (not got_chunk
                              and stdout.channel.exit_status_ready()
                              and not stderr.channel.recv_stderr_ready()
                              and not stdout.channel.recv_ready()):
                          # Indicate that we're not going to read from
                          # this channel anymore
                          stdout.channel.shutdown_read()
                          # close the channel
                          stdout.channel.close()
                          # Remote side is finished & our bufferes are empty
                          break
  
              # close all the pseudofiles
              stdout.close()
              stderr.close()
  
              if wait_result:
                  # exit code is always ready at this point
                  exit_code = stdout.channel.recv_exit_status()
                  output = ''.join([b.decode() for b in stdout_chunks])
                  return output, exit_code
              else:
                  return True
          else:
              if wait_result:
                  return None, None
              else:
                  return False
code_tokens: def send_command ( self , command , exec_timeout = 3000 , read_chunk_timeout = 500 , wait_result = False ) : if self . _client is not None : if self . _login_shell : cmd = "bash -l -c {}" . format ( shlex_quote ( command ) ) else : cmd = command retries = 3 while True : try : stdin , stdout , stderr = self . _client . exec_command ( cmd , timeout = exec_timeout ) except ( SSHException , socket . error ) as se : if retries > 0 : retries -= 1 logging . getLogger ( "paramiko" ) . warning ( "Retrying SSH connection: " + str ( se ) ) continue else : raise se break if wait_result : channel = stdout . channel stdin . close ( ) channel . shutdown_write ( ) stdout_chunks = [ ] stdout_chunks . append ( stdout . channel . recv ( len ( stdout . channel . in_buffer ) ) ) stdout_chunks . append ( stderr . channel . recv ( len ( stderr . channel . in_buffer ) ) ) while ( not channel . closed or channel . recv_ready ( ) or channel . recv_stderr_ready ( ) ) : got_chunk = False readq , _ , _ = select . select ( [ stdout . channel ] , [ ] , [ ] , read_chunk_timeout ) for c in readq : if c . recv_ready ( ) : stdout_chunks . append ( stdout . channel . recv ( len ( c . in_buffer ) ) ) got_chunk = True if c . recv_stderr_ready ( ) : stdout_chunks . append ( stderr . channel . recv_stderr ( len ( c . in_stderr_buffer ) ) ) got_chunk = True """
                      1) make sure that there are at least 2 cycles with no data
                          in the input buffers in order to not exit too early
                          (i.e. cat on a >200k file).
                      2) if no data arrived in the last loop, check if we already
                          received the exit code
                      3) check if input buffers are empty
                      4) exit the loop
                      """ if ( not got_chunk and stdout . channel . exit_status_ready ( ) and not stderr . channel . recv_stderr_ready ( ) and not stdout . channel . recv_ready ( ) ) : stdout . channel . shutdown_read ( ) stdout . channel . close ( ) break stdout . close ( ) stderr . close ( ) if wait_result : exit_code = stdout . channel . recv_exit_status ( ) output = '' . join ( [ b . decode ( ) for b in stdout_chunks ] ) return output , exit_code else : return True else : if wait_result : return None , None else : return False
short_docstring: Sends a command and returns stdout, stderr and exitcode
short_docstring_tokens: Sends a command and returns stdout stderr and exitcode
comment: """Sends a command and returns stdout, stderr and exitcode"""$SEP$# Check if connection is made previously$SEP$# there is one channel per command$SEP$# get the shared channel for stdout/stderr/stdin$SEP$# we do not need stdin$SEP$# indicate that we're not going to write to that channel$SEP$# read stdout/stderr in order to prevent read block hangs$SEP$# chunked read to prevent stalls$SEP$# Stop if channel was closed prematurely,$SEP$# and there is no data in the buffers.$SEP$# make sure to read stderr to prevent stall$SEP$"""
                      1) make sure that there are at least 2 cycles with no data
                          in the input buffers in order to not exit too early
                          (i.e. cat on a >200k file).
                      2) if no data arrived in the last loop, check if we already
                          received the exit code
                      3) check if input buffers are empty
                      4) exit the loop
                      """$SEP$# Indicate that we're not going to read from$SEP$# this channel anymore$SEP$# close the channel$SEP$# Remote side is finished & our bufferes are empty$SEP$# close all the pseudofiles$SEP$# exit code is always ready at this point