Skip to content
Back to top
View this page
Edit this page

# xonsh.procs.readers

File handle readers and related tools.

class xonsh.procs.readers.BufferedFDParallelReader(fd, buffer=None, chunksize=1024)

  Buffered, parallel background thread reader.

  Parameters:
    fd int

      File descriptor from which to read.

    buffer binary file-like or None, optional

      A buffer to write bytes into. If None, a new BytesIO object is created.

    chunksize int, optional

      The max size of the parallel reads, default 1 kb.

class xonsh.procs.readers.ConsoleParallelReader(fd, buffer=None, chunksize=1024, timeout=None)

  Parallel reader for consoles that runs in a background thread. This is only needed, available, and useful on Windows.

  Parameters:
    fd int

      Standard buffer file descriptor, 0 for stdin, 1 for stdout (default), and 2 for stderr.

    buffer ctypes.c_wchar_p, optional

      An existing buffer to (re-)use.

    chunksize int, optional

      The max size of the parallel reads, default 1 kb.

    timeout float, optional

      The queue reading timeout.

  static readable()

    Returns true, because this object is always readable.

  close()

    close the reader

  fileno()

    Returns the file descriptor number.

  is_fully_read()

    Returns whether or not the queue is fully read and the reader is closed.

  iterqueue()

    Iterates through all remaining chunks in a blocking fashion.

  read(size=-1)

    Reads bytes from the file.

  read_queue()

    Reads a single chunk from the queue. This is blocking if the timeout is None and non-blocking otherwise.

  readline(size=-1)

    Reads a line, or a partial line from the file descriptor.

  readlines(hint=-1)

    Reads lines from the file descriptor. This is blocking for negative hints (i.e. read all the remaining lines) and non-blocking otherwise.

class xonsh.procs.readers.NonBlockingFDReader(fd, timeout=None)

  A class for reading characters from a file descriptor on a background thread. This has the advantages that the calling thread can close the file and that the reading does not block the calling thread.

  Parameters:
    fd int

      A file descriptor

    timeout float or None, optional

      The queue reading timeout.

  static readable()

    Returns true, because this object is always readable.

  close()

    close the reader

  fileno()

    Returns the file descriptor number.

  is_fully_read()

    Returns whether or not the queue is fully read and the reader is closed.

  iterqueue()

    Iterates through all remaining chunks in a blocking fashion.

  read(size=-1)

    Reads bytes from the file.

  read_queue()

    Reads a single chunk from the queue. This is blocking if the timeout is None and non-blocking otherwise.

  readline(size=-1)

    Reads a line, or a partial line from the file descriptor.

  readlines(hint=-1)

    Reads lines from the file descriptor. This is blocking for negative hints (i.e. read all the remaining lines) and non-blocking otherwise.

class xonsh.procs.readers.QueueReader(fd, timeout=None)

  Provides a file-like interface to reading from a queue.

  Parameters:
    fd int

      A file descriptor

    timeout float or None, optional

      The queue reading timeout.

  static readable()

    Returns true, because this object is always readable.

  close()

    close the reader

  fileno()

    Returns the file descriptor number.

  is_fully_read()

    Returns whether or not the queue is fully read and the reader is closed.

  iterqueue()

    Iterates through all remaining chunks in a blocking fashion.

  read(size=-1)

    Reads bytes from the file.

  read_queue()

    Reads a single chunk from the queue. This is blocking if the timeout is None and non-blocking otherwise.

  readline(size=-1)

    Reads a line, or a partial line from the file descriptor.

  readlines(hint=-1)

    Reads lines from the file descriptor. This is blocking for negative hints (i.e. read all the remaining lines) and non-blocking otherwise.

xonsh.procs.readers.populate_buffer(reader, fd, buffer, chunksize)

  Reads bytes from the file descriptor and copies them into a buffer.

  The reads happen in parallel using the pread() syscall; which is only available on POSIX systems. If the read fails for any reason, the reader is flagged as closed.

xonsh.procs.readers.populate_console(reader, fd, buffer, chunksize, queue, expandsize=None)

  Reads bytes from the file descriptor and puts lines into the queue. The reads happened in parallel, using xonsh.winutils.read_console_output_character(), and is thus only available on windows. If the read fails for any reason, the reader is flagged as closed.

xonsh.procs.readers.populate_fd_queue(reader, fd, queue)

  Reads 1 kb of data from a file descriptor into a queue. If this ends or fails, it flags the calling reader object as closed.

xonsh.procs.readers.safe_fdclose(handle, cache=None)

  Closes a file handle in the safest way possible, and potentially storing the result.