queuefile

This module defines the QueueFile class.

class turboctl.ui.queuefile.QueueFile(block=False)

This class wraps a queue.Queue object in the interface of a file-like object.

The QueueFile class makes redirecting input and output between different parts of a program easier than it would be using standard file objects, such as io.StringIO or those created by pty.openpty(). QueueFile is thread-safe, can be read from and written to at the same time, and its blocking behaviour can be easily controlled. (If there is nothing to read, reading from io.StringIO never blocks, but reading from an object created with pty.openpty() always does.)

queue

The wrapped Queue object. Strings are saved in the queue one character at a time.

Type:

queue.Queue

block

A flag indicating whether read() and readline() should block or not.

Type:

bool

__init__(block=False)

Intialize a new QueueFile with block set to the value given as an argument.

write(string)

Write string to the queue and return the number of characters written.

This method emulates io.TextIOBase.write().

read(size=- 1)

Read and return a string of size characters from the queue.

If the queue contains less than size characters or size is None or less than 1, all characters in the queue are read.

This method emulates io.TextIOBase.read().

readline(size=- 1)

Like read(), but reading characters is stopped if a newline character is encountered. If this happens, the string returned includes that newline character.

This method emulates io.TextIOBase.readline().

flush()

This method does nothing, but its existence makes it possible to print() to this object with flush=True without raising an AttributeError.