What should go to stdout/stderr and why Python logging write everything to stderr?

Chris Angelico rosuav at gmail.com
Wed Jan 4 01:46:26 EST 2023


On Wed, 4 Jan 2023 at 17:26, Eryk Sun <eryksun at gmail.com> wrote:
>
> On 1/3/23, Chris Angelico <rosuav at gmail.com> wrote:
> >
> > FDs can also be buffered. If it's buffering you want to avoid, don't
> > mess around with exactly which one you're writing to, just flush.
>
> I meant to flush a C FILE stream or Python file before writing
> directly to the file descriptor, in order to avoid out-of-sequence and
> interlaced writes that make no sense. Any OS buffering on the file
> doesn't matter in this regard.

True, that can help. If you're about to prompt for a password, though,
OS buffering can most certainly make a difference. And it doesn't hurt
to explicitly flush when you need it flushed.

I've known some systems to have a trigger of "reading on FD 0 flushes
FD 1", but that's not going to work when you use certain
keyboard-input routines (ISTR readline was one of the few things that
*didn't* have that problem, but I may be misremembering), so the
general strategy was: print your prompt, flush stdout, THEN request
input.

ChrisA


More information about the Python-list mailing list