How to flush <stdio.h>'s stdout stream?

Grant Edwards grant.b.edwards at gmail.com
Fri Jan 15 13:40:37 EST 2021


In Python 3.7+, how does one flush the stdout FILE stream? I mean the
FILE *declared as 'stdio' in <stdio.h>. I'm _not_ asking how to flush the
Python file object sys.stdio.

The problem is that some Python modules write to FILE *stdio, but
don't flush the stream so that the data gets written to the standard
output file descriptor (fd 1). If you need to interleave the output
from those modules with writes from other Python code to fd 1 (via
sys.stdout or whatever), you need a way to flush FILE *stdio.

I know how to use ctypels to call fflush(), but I can't figure out how
to get the FILE *stdio value to pass to fflush().

Is there some os.??? or sys.??? function that I've missed?





More information about the Python-list mailing list