pymemtrace.redirect_stdout

Taken from the excellent blog: https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/

Changes:

  • Minor edits.

  • Move tfile = tempfile.TemporaryFile(mode=’w+b’) outside try block.

  • Duplicate for stderr

TODO: Unite duplicate code.

pymemtrace.redirect_stdout.stderr_redirector(stream: BinaryIO)[source]

A context manager that redirects Python stderr and C stderr to the given binary I/O stream.

pymemtrace.redirect_stdout.stdout_redirector(stream: BinaryIO)[source]

A context manager that redirects Python stdout and C stdout to the given binary I/O stream.