Python: Suppress library output not using stdout

573 views Asked by At

I am having problems using pyVisa library for port communication, because it sometimes output alot of repeated information to the console (e.G):

Comm::LockCheck: sess=122e248, isDevSess=0, locssess=0, pid=6220, lockpid=0

Devsess can be locked.

Intfsess can be locked.

I have tried redirecting stdout as suggested in alot of other post (e.g):

@contextlib.contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devnull:
    old_stdout = sys.stdout
    sys.stdout = devnull
    try:  
        yield
    finally:
        sys.stdout = old_stdout 

This suppresses my own print commands when used, but does not prevent the library from printing.

Preferably any suggestion should be safe to use in Thread. (I known that the attempted code is not)

0

There are 0 answers