logging
Utility functions for logging.
Classes
Mirror a text stream to sink while passing writes through to stream. |
Functions
Decorator to prevent interleaved output in distributed/multi-threaded environments. |
|
Capture stdout and stderr within the invoked context. |
|
Silences stdout within the invoked context. |
|
Convert big floating number to human readable string. |
|
Pretty-print an |
|
Prints only on the master process. |
|
Silences warnings that match a given pattern. |
|
Issues a warning only on the master process. |
- exception DeprecatedError
Bases:
NotImplementedErrorError for deprecated functions.
- class TeeStream
Bases:
objectMirror a text stream to sink while passing writes through to stream.
Scripts that report progress with bare
print()have no log file; wrappingsys.stdout/sys.stderrin this is what produces one. Attribute access falls through to the wrapped stream soisatty()keeps progress bars behaving. Native (C-level) writes go straight to the real file descriptor and are not captured.- __init__(stream, sink)
Wrap stream, mirroring everything written to it into the open file sink.
- flush()
Flush both the original stream and the sink.
- Return type:
None
- write(data)
Write to both the original stream and the sink.
- Parameters:
data (str)
- Return type:
int
- atomic_print(func)
Decorator to prevent interleaved output in distributed/multi-threaded environments.
- capture_io(capture_stderr=True)
Capture stdout and stderr within the invoked context.
- Parameters:
capture_stderr (bool) – Whether to capture stderr. Defaults to True.
- Returns:
An iterator that yields a StringIO object that contains the captured output.
- Return type:
Iterator[StringIO]
Example:
with capture_io() as buf: print("Hello, world!") print(buf.getvalue())
- no_stdout()
Silences stdout within the invoked context.
- num2hrb(num, suffix='')
Convert big floating number to human readable string.
- Parameters:
num (float)
- Return type:
str
- print_args(args, title='Arguments')
Pretty-print an
argparse.Namespace(one entry per line) on rank 0.- Parameters:
args (Namespace)
title (str)
- Return type:
None
- print_rank_0(*args, **kwargs)
Prints only on the master process.
- silence_matched_warnings(pattern=None)
Silences warnings that match a given pattern.
- Parameters:
pattern (str) – The pattern to match against warning messages. Defaults to None.
- warn_rank_0(message, *args, **kwargs)
Issues a warning only on the master process.
Auto-bumps
stacklevelby 1 to skip this wrapper frame, so callers can pass the same stacklevel they would towarnings.warndirectly and the warning still points at the user’s call site.