feat: add context manager to suppress print from e.g. macros

This commit is contained in:
2026-07-13 12:49:28 +02:00
parent 6b2bbd17e3
commit 443b6035ba
+12
View File
@@ -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