@contextmanager
def silence_stderr():
 if DEBUG:
  (yield)
 else:
  with threading.Lock():
   stderr = sys.stderr
   sys.stderr = StringIO()
  (yield)
  with threading.Lock():
   sys.stderr = 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
redirect stderr .