redirect_fd

(class from pyomo.common.tee)

class pyomo.common.tee.redirect_fd(fd=1, output=None, synchronize=True)[source]

Bases: object

Redirect a file descriptor to a new file or file descriptor.

This context manager will redirect the specified file descriptor to a specified new output target (either file name or file descriptor). For the special case of file descriptors 1 (stdout) and 2 (stderr), we will also make sure that the Python sys.stdout or sys.stderr remain usable: in the case of synchronize=True, the sys.stdout / sys.stderr file handles point to the new file descriptor. When synchronize=False, we preserve the behavior of the Python file object (retargeting it to the original file descriptor if necessary).

Parameters:
  • fd (int) – The file descriptor to redirect

  • output (int or str) – The new output target for fd: either another valid file descriptor (int) or a string with the file to open.

  • synchronize (bool) – If True, and fd is 1 or 2, then update sys.stdout or sys.stderr to also point to the new file descriptor

__init__(fd=1, output=None, synchronize=True)[source]

Methods

__init__([fd, output, synchronize])

Member Documentation