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 asio.StringIO
or those created bypty.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 fromio.StringIO
never blocks, but reading from an object created withpty.openpty()
always does.)- block¶
A flag indicating whether
read()
andreadline()
should block or not.- Type:
- 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 than1
, 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 withflush=True
without raising anAttributeError
.