Simplify redirect of stdout.

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

def stdout_redirector():
    """
    Simplify redirect of stdout.

    Taken from here: https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/
    """
    old_stdout = sys.stdout
    sys.stdout = Stream()
    try:
        yield sys.stdout
    finally:
        sys.stdout.close()
        sys.stdout = old_stdout