Solved by mrshenli in post #3 
              
              
                If you want to suppress both stdout and stderr outputs, you can try this: 
import sys, os

f = open(os.devnull, "w")
if rank != 0:
    sys.stdout = f
    sys.stderr = f