class_docstr: This is the main class interface for Pexpect. Use this class to start
  and control child applications. 
class_docstr_tok: ["This","is","the","main","class","interface","for","Pexpect",".","Use","this","class","to","start","and","control","child","applications","."]
docstr: This reads at most size characters from the child application. It
  includes a timeout. If the read does not complete within the timeout
  period then a TIMEOUT exception is raised. If the end of file is read
  then an EOF exception will be raised.  If a logfile is specified, a
  copy is written to that log.
  
  If timeout is None then the read may block indefinitely.
  If timeout is -1 then the self.timeout value is used. If timeout is 0
  then the child is polled and if there is no data immediately ready
  then this will raise a TIMEOUT exception.
  
  The timeout refers only to the amount of time to read at least one
  character. This is not affected by the 'size' parameter, so if you call
  read_nonblocking(size=100, timeout=30) and only one character is
  available right away then one character will be returned immediately.
  It will not wait for 30 seconds for another 99 characters to come in.
  
  On the other hand, if there are bytes available to read immediately,
  all those bytes will be read (up to the buffer size). So, if the
  buffer size is 1 megabyte and there is 1 megabyte of data available
  to read, the buffer will be filled, regardless of timeout.
  
  This is a wrapper around os.read(). It uses select.select() or
  select.poll() to implement the timeout. 
docstr_tok: ["This","reads","at","most","size","characters","from","the","child","application",".","It","includes","a","timeout",".","If","the","read","does","not","complete","within","the","timeout","period","then","a","TIMEOUT","exception","is","raised",".","If","the","end","of","file","is","read","then","an","EOF","exception","will","be","raised",".","If","a","logfile","is","specified",",","a","copy","is","written","to","that","log",".","If","timeout","is","None","then","the","read","may","block","indefinitely",".","If","timeout","is","-1","then","the","self.timeout","value","is","used",".","If","timeout","is","0","then","the","child","is","polled","and","if","there","is","no","data","immediately","ready","then","this","will","raise","a","TIMEOUT","exception",".","The","timeout","refers","only","to","the","amount","of","time","to","read","at","least","one","character",".","This","is","not","affected","by","the","'size","'","parameter",",","so","if","you","call","read_nonblocking","(","size=100",",","timeout=30",")","and","only","one","character","is","available","right","away","then","one","character","will","be","returned","immediately",".","It","will","not","wait","for","30","seconds","for","another","99","characters","to","come","in",".","On","the","other","hand",",","if","there","are","bytes","available","to","read","immediately",",","all","those","bytes","will","be","read","(","up","to","the","buffer","size",")",".","So",",","if","the","buffer","size","is","1","megabyte","and","there","is","1","megabyte","of","data","available","to","read",",","the","buffer","will","be","filled",",","regardless","of","timeout",".","This","is","a","wrapper","around","os.read","(",")",".","It","uses","select.select","(",")","or","select.poll","(",")","to","implement","the","timeout","."]
code: def read_nonblocking(self, size=1, timeout=-1):
      """This reads at most size characters from the child application. It
      includes a timeout. If the read does not complete within the timeout
      period then a TIMEOUT exception is raised. If the end of file is read
      then an EOF exception will be raised.  If a logfile is specified, a
      copy is written to that log.
  
      If timeout is None then the read may block indefinitely.
      If timeout is -1 then the self.timeout value is used. If timeout is 0
      then the child is polled and if there is no data immediately ready
      then this will raise a TIMEOUT exception.
  
      The timeout refers only to the amount of time to read at least one
      character. This is not affected by the 'size' parameter, so if you call
      read_nonblocking(size=100, timeout=30) and only one character is
      available right away then one character will be returned immediately.
      It will not wait for 30 seconds for another 99 characters to come in.
  
      On the other hand, if there are bytes available to read immediately,
      all those bytes will be read (up to the buffer size). So, if the
      buffer size is 1 megabyte and there is 1 megabyte of data available
      to read, the buffer will be filled, regardless of timeout.
  
      This is a wrapper around os.read(). It uses select.select() or
      select.poll() to implement the timeout."""
  
      if self.closed:
          raise ValueError("I/O operation on closed file.")
  
      if self.use_poll:
  
          def select(timeout):
              return poll_ignore_interrupts([self.child_fd], timeout)
  
      else:
  
          def select(timeout):
              return select_ignore_interrupts(
                  [self.child_fd], [], [], timeout
              )[0]
  
      # If there is data available to read right now, read as much as
      # we can. We do this to increase performance if there are a lot
      # of bytes to be read. This also avoids calling isalive() too
      # often. See also:
      # * https://github.com/pexpect/pexpect/pull/304
      # * http://trac.sagemath.org/ticket/10295
      if select(0):
          try:
              incoming = super(spawn, self).read_nonblocking(size)
          except EOF:
              # Maybe the child is dead: update some attributes in that case
              self.isalive()
              raise
          while len(incoming) < size and select(0):
              try:
                  incoming += super(spawn, self).read_nonblocking(
                      size - len(incoming)
                  )
              except EOF:
                  # Maybe the child is dead: update some attributes in that case
                  self.isalive()
                  # Don't raise EOF, just return what we read so far.
                  return incoming
          return incoming
  
      if timeout == -1:
          timeout = self.timeout
  
      if not self.isalive():
          # The process is dead, but there may or may not be data
          # available to read. Note that some systems such as Solaris
          # do not give an EOF when the child dies. In fact, you can
          # still try to read from the child_fd -- it will block
          # forever or until TIMEOUT. For that reason, it's important
          # to do this check before calling select() with timeout.
          if select(0):
              return super(spawn, self).read_nonblocking(size)
          self.flag_eof = True
          raise EOF("End Of File (EOF). Braindead platform.")
      elif self.__irix_hack:
          # Irix takes a long time before it realizes a child was terminated.
          # Make sure that the timeout is at least 2 seconds.
          # FIXME So does this mean Irix systems are forced to always have
          # FIXME a 2 second delay when calling read_nonblocking? That sucks.
          if timeout is not None and timeout < 2:
              timeout = 2
  
      # Because of the select(0) check above, we know that no data
      # is available right now. But if a non-zero timeout is given
      # (possibly timeout=None), we call select() with a timeout.
      if (timeout != 0) and select(timeout):
          return super(spawn, self).read_nonblocking(size)
  
      if not self.isalive():
          # Some platforms, such as Irix, will claim that their
          # processes are alive; timeout on the select; and
          # then finally admit that they are not alive.
          self.flag_eof = True
          raise EOF("End of File (EOF). Very slow platform.")
      else:
          raise TIMEOUT("Timeout exceeded.")
  
imports: import os
  import sys
  import time
  import pty
  import tty
  import errno
  import signal
  from contextlib import contextmanager
  import ptyprocess
  from ptyprocess.ptyprocess import use_native_pty_fork
  from .exceptions import ExceptionPexpect, EOF, TIMEOUT
  from .spawnbase import SpawnBase
  from .utils import which, split_command_line, select_ignore_interrupts, poll_ignore_interrupts
label_desc: Use image node_id 10 for calling the spawn obj's underlying member method code with example usage: obj.read_nonblocking(size, timeout) and returns: incoming, super, poll_ignore_interrupts, select_ignore_interrupts, super, incoming