feat: add context manager to suppress print from e.g. macros
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import os
|
||||
from contextlib import contextmanager, redirect_stderr, redirect_stdout
|
||||
|
||||
|
||||
@contextmanager
|
||||
def suppress_output():
|
||||
"""Suppress both stdout and stderr by redirecting them to os.devnull."""
|
||||
# Note that this shouldn't catch logs as well: https://github.com/python/cpython/issues/123481
|
||||
# it is intended for suppressing print output from macros called by the DAQ server
|
||||
with open(os.devnull, "w") as fnull:
|
||||
with redirect_stdout(fnull), redirect_stderr(fnull):
|
||||
yield
|
||||
Reference in New Issue
Block a user