This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Via Stack Overflow | |
| # https://stackoverflow.com/questions/11130156/suppress-stdout-stderr-print-from-python-functions | |
| from contextlib import contextmanager,redirect_stderr,redirect_stdout | |
| from os import devnull | |
| @contextmanager | |
| def suppress_stdout_stderr(): | |
| """A context manager that redirects stdout and stderr to devnull""" | |
| with open(devnull, 'w') as fnull: | |
| with redirect_stderr(fnull) as err, redirect_stdout(fnull) as out: |