3

I`m using Prophet (Time series library by Facebook) and it makes a lot of output. Something like this: Prophet output

I`m already silent some output like this:

@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

But it doesn't silent all types of output, how I can silent all types?

josqa
  • 31
  • 6

2 Answers2

2

The problem here is the Prophet several loggers, which you can silent with:

import logging
logging.getLogger("prophet").setLevel(logging.ERROR)
logging.getLogger("cmdstanpy").setLevel(logging.ERROR)
Pedro Muñoz
  • 590
  • 5
  • 11
1

I suspect you are using an IPython-like environment e.g. Jupyter notebook. Then you can use the %%capture magic command in a cell.

For example,

%%capture
output = do_some_verbose_things(args)

By default it also captures the stderr which I think the outputs you see are going there.

  • Unfortunately, output like: "INFO:fbprophet:Making 4 forecasts with cutoffs between..." (from my screenshot) still visible. – josqa Apr 08 '21 at 12:57
  • @josqa Interesting. then please check the functions you are using from that package, they might have some `verbose` or `silent` parameter. You can adjust them e.g. `verbose=0` or `silent=True`. I'm not familiar with that library and you did not share the codes producing so i'm not sure if they have such parameters. –  Apr 08 '21 at 13:07
  • Thank you! Yeah, I`m checked this firstly, there is no such parameters. – josqa Apr 08 '21 at 13:22