sys.stdout.flush()
newstdout = os.dup(1)
devnull = os.open('/dev/null', os.O_WRONLY)
os.dup2(devnull, 1)
os.close(devnull)
sys.stdout = os.fdopen(newstdout, 'w')
Redirect stdout from python for C calls