@contextmanager
def silence_stderr():
    ' Redirect stderr. '
    if DEBUG:
        (yield)
    else:
        with threading.Lock():
            stderr = sys.stderr
            sys.stderr = StringIO()
        (yield)
        with threading.Lock():
            sys.stderr = stderr
Redirect stderr.
@contextmanager
def silence_stderr():
    '  '
    if DEBUG:
        (yield)
    else:
        with threading.Lock():
            stderr = sys.stderr
            sys.stderr = StringIO()
        (yield)
        with threading.Lock():
            sys.stderr = stderr