triqs.utility.redirect

Pipe-based redirection of the C++ stdout back to Python.

The C++ side of TRIQS writes to file descriptor 1 directly, which sys.stdout redirection from Python does not capture (in particular, Jupyter only sees writes that go through Python). This module installs a background threading.Thread that

  1. duplicates the original file descriptor 1 so it can be restored later,

  2. creates a pipe and dup2 its write end onto descriptor 1, so all subsequent C++ output goes into the pipe,

  3. periodically reads from the pipe (non-blocking) and writes the bytes back to Python’s sys.stdout.

The public API is start_redirect() and stop_redirect(); they are idempotent and toggle the module-level started flag.

Attributes

startedbool

True while a redirection thread is running. Set by start_redirect() and cleared by stop_redirect().

Functions

start_redirect()

Start a background thread that redirects the C++ stdout to Python.

stop_redirect()

Stop the background redirection thread started by start_redirect().

Classes

T()

Background thread that pumps the C++ stdout into Python's.