Suppress python warnings in system-wide or cron-wide

I have many python scripts that generate

/home/intranet/public_html/intranet/bin/utils.py:172: DeprecationWarning: os.popen4 is deprecated. Use the subprocess module. fin, fout = os.popen4(cmd) 

and other warnings.

Is there any way to hide them in system or cron-wide?

Thanks!

+4
source share
2 answers

Any other DeprecationWarning s? Run the script as follows:

 python -W ignore::DeprecationWarning thescript.py 

If you want to ignore all warnings, use

 python -W ignore thescript.py 

To ignore warnings in the system or in width, set the env variable PYTHONWARNINGS :

 PYTHONWARNINGS=ignore::DeprecationWarning # or PYTHONWARNINGS=ignore 

Documentation: Option -W and PYTHONWARNINGS .

What version of python are you using? An invalid warning value should be ignored by default in 2.7.

+4
source

If you don't want to output when running programs via cron, you just need to add >/dev/null 2>&1 to the end of the line of execution. This will redirect your normal output to zero, but also to errors.

0
source

All Articles