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
duplicates the original file descriptor
1so it can be restored later,creates a pipe and
dup2its write end onto descriptor1, so all subsequent C++ output goes into the pipe,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
Truewhile a redirection thread is running. Set bystart_redirect()and cleared bystop_redirect().
Functions
Start a background thread that redirects the C++ |
|
Stop the background redirection thread started by |
Classes
|
Background thread that pumps the C++ |