Exploring terminfo

Chris Angelico rosuav at gmail.com
Sat Jan 16 18:40:59 EST 2021


On Sun, Jan 17, 2021 at 10:36 AM Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>
> On 16/01/21 4:17 pm, Chris Angelico wrote:
> > But somewhere along the way, you're finding that there's a problem,
> > which implies that SOMETHING is calling on C stdio. That thing,
> > surely, should be the thing responsible for flushing?
>
> The C library using stdio has no way of knowing that something
> else (e.g. Python) is bypassing stdio. That's an unusual thing
> to do in the C world, so you can't really blame the authors
> of the library for failing to anticipate it.
>
> It's also unreasonable to expect a C library to flush after
> every write, as that would defeat the purpose of stdio buffering.
>

This is true. However, at some point, the boundary is crossed from
Python into the C library. Something, at that point, knows. It's very
common to have a flush option available, so it should be used.

It's extremely uncommon for Python to call into C code that (a) uses C
stdio, (b) shares the file handle with something else (eg
stdout/stderr), and (c) doesn't have an option to flush its output.
And when that happens, I would consider it a bug, not just because of
the shared handle - if you're piping the output into something else,
you might need to force it to flush its buffer.

ChrisA


More information about the Python-list mailing list