stouputils.ctx.fd_capture module#
Copying into a log what reaches the stdout and stderr file descriptors without going through sys.stdout.
C extensions, os.system and child processes that do not capture their output write straight to the descriptors,
so replacing sys.stdout never sees them. FdCapture points the descriptors at a pseudo-terminal, or a pipe when the
output is not a terminal, and a thread copies what arrives both to the real terminal and into the log.
- class FdChannel(
- fd: int,
- saved: int,
- reader: int,
- target: TeeTarget,
- decoder: IncrementalDecoder = <factory>,
Bases:
objectOne redirected descriptor: where it pointed before, and the end the reader thread reads it from.
- class FdCapture(
- file: IO[Any],
- strip_colors: bool,
- ignore_lineup: bool,
Bases:
objectCopy everything written to the stdout and stderr descriptors into a log file, the terminal still showing it.
Python’s own output reaches the descriptors too, so the log receives every line in the order it was written. The reader thread never stops on an error, since a full pipe would block every later write of the program.
- Parameters:
file – Log file receiving the text.
strip_colors – Whether the log receives the text without ANSI colors.
ignore_lineup – Whether the log receives what a terminal ends up showing, see
LineState.
- static unsupported_reason() str | None[source]#
Why the descriptors cannot be captured here, None when they can.
- stop() None[source]#
Give the descriptors back, then let the reader thread copy what is left before it ends.
- flush_all() None[source]#
Flush Python’s streams and the C library’s, so what they hold goes through the descriptors now.