Source code for CDTK.Tools.OutputGrabber


import threading
import time
from contextlib import contextmanager
import os
import sys

[docs] @contextmanager def suppress_stdout(): with open(os.devnull, "w") as devnull: old_stdout = os.dup(sys.stdout.fileno()) os.dup2(devnull.fileno(), sys.stdout.fileno()) try: yield finally: os.dup2(old_stdout, sys.stdout.fileno())
[docs] @contextmanager def suppress_stdoutstderr(): with open(os.devnull, "w") as devnull: old_stdout = os.dup(sys.stdout.fileno()) old_stderr = os.dup(sys.stderr.fileno()) os.dup2(devnull.fileno(), sys.stdout.fileno()) os.dup2(devnull.fileno(), sys.stderr.fileno()) try: yield finally: os.dup2(old_stdout, sys.stdout.fileno()) os.dup2(old_stderr, sys.stderr.fileno())