Print executed lines to stdout.

def tracing(pattern=None, out=None):
    """Print executed lines to stdout."""
    _trace = partial(trace_line, pattern)

    if out is None:
        out = sys.stdout

    with redirect_stdout(out):
        sys.settrace(_trace)
        try:
            yield
        finally:
            sys.settrace(None)