Module trase.tools.sei_pcs.utilities

Functions

def display_top(snapshot, limit=20)
def tee(filename, mode='a', prefix='[%H:%M:%S] ', open_kwargs=None, stdout=True, stderr=True)

Capture stdout and/or stderr and write to to both a file and to stdout.

We also prefix every line with a timestamp. By default both stdout and sterr are captured, and they are both sent to stdout.

Example

The following code:

with tee("my_log.txt"):
   print("this is your captain speaking")

Will result in the following being written to both the console and "my_log.txt"

[15:09:08] this is your captain speaking

Args

filename : str
path to the file that should be opened
mode : str, optional
file opening mode, e.g "w" or "a"
open_kwargs : dict, optional
other keyword arguments passed to Python's open built-in
prefix : str, optional
an optional prefix that will be passed to datetime.strftime, or None if there should be no prefix
stdout : bool, optional
whether to capture stdout
stderr : bool, optional
whether to capture stderr
def trace_memory_allocation(func)