Hide terminal output when importing gymtorch

Every time gymtorch is imported, I get terminal output like this:

Importing module 'gym_37' (/home/adam/source_code/isaacgym/python/isaacgym/_bindings/linux-x86_64/gym_37.so)
Setting GYM_USD_PLUG_INFO_PATH to /home/adam/source_code/isaacgym/python/isaacgym/_bindings/linux-x86_64/usd/plugInfo.json
PyTorch version 1.7.1
Device count 1
Current device 0
/home/adam/source_code/isaacgym/python/isaacgym/_bindings/src/gymtorch
Using /home/adam/.cache/torch_extensions as PyTorch extensions root...
Emitting ninja build file /home/adam/.cache/torch_extensions/gymtorch/build.ninja...
Building extension module gymtorch...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
ninja: no work to do.
Loading extension module gymtorch...

Is there an easy way to prevent all of this from printing to the terminal? My issue now is I’m using the multiprocessing package to alternate running the simulator and training a model. However, for some reason on every epoch of training the model it re-imports gymtorch (I’m not sure why that’s happening, each new epoch is still in the same process) and my terminal is getting polluted with the gymtorch output. Any thoughts on how to prevent that text from displaying?

I have a way to get rid of most of it by suppressing stdout (from this blog):

import os
import sys
from contextlib import contextmanager

@contextmanager
def suppress_stdout():
    """
    Suppresses printing to stdout within the context. Useful when there 
    is annoying terminal printing you can't seem to prevent.

    Usage:        
        with suppress_stdout():
            print("This won't show up in terminal")

    Credit: http://thesmithfam.org/blog/2012/10/25/temporarily-suppress-console-output-in-python/
    """
    with open(os.devnull, "w") as devnull:
        old_stdout = sys.stdout
        sys.stdout = devnull
        try:  
            yield
        finally:
            sys.stdout = old_stdout

I use that context manager when I import anything from isaacgym to suppress it. I still get the ninja: no work to do., I’m not sure how to handle that one as I tried suppressing both stdout and stderr and still got it.

1 Like