Flushing stdout with raw_input - BUG

Michael Hudson mwh at python.net
Wed Mar 6 09:17:03 EST 2002


Jonathan Gardner <jgardn at alumni.washington.edu> writes:

> raw_input and several modules that are part of the standard library that 
> handle input and output with stdout and stdin (cmd.py) do NOT - I repeat - 
> do NOT flush stdout before waiting for input.
> 
> No, I don't want to flush buffer stdout everytime I write to it. That is 
> wasteful and inefficient. I want to flush the buffer when I am done writing 
> to it, or when I make a call to raw_input(). (This has been brought up 
> before a long time ago - why is it not fixed? Why does Guido want it to 
> behave like this?)
> 
> If it is running with a terminal, then the underlying code (in C or the 
> Kernel, I am not sure) will flush stdout before reading input. However, it 
> does not automatically flush stdout before reading stdin if stdout and 
> stdin are not terminals.
> 
> That means if I write a program that forks off another process that runs a 
> python script that uses stdin and stdout, (using something like Popen3), 
> then the conversation goes something like this:
[snip melodrama]
> Should I turn on -u for the child script? That is silly. Just write
> raw_input properly, and make everyone happy. If you don't, I'll be
> *forced* to hack on the cpython code, and then you'll *really*
> regret it! =)

Not necessarily -- you could use a pseudo terminal.  That way the
child will think it's talking to a terminal, and so things will be
line buffered.

> I am running Linux 2.4.14 and Python 2.1.2. I tested this bug in Python 2.2 
> and it is still there.
> 
> I posted a bug about cmd not flushing the buffer to sourceforge. I will 
> post another bug about raw_input not flushing the buffer. I will write 
> another bug report about the unresponsiveness to bug reports as well, as 
> there are a lot of bugs that aren't even addressed at sourceforge.

Oh, that will help, sure.

Please note that Python is a volunteer effort.  You have no right to
expect bug reports to be attended to.

However, they are.  I know *I* scan through open bugs fairly
regularly.  Martin von Loewis does the same.  I can only fix the bugs
I have time to fix, and so fix the bugs that seem to me to be worth
fixing.  I've spent multiple hours in just the past few days with my
head stuck deep in the Python internals, and TBH posts like this do
not make me think it was worth it.

> PLEASE PLEASE PLEASE! Examine your code. If you do not use raw_input, then 
> flush your buffers! Otherwise, we will not be able to fork off your 
> script/module and use it as a child process without -u.

If you are interacting with a subprocess that is expecting to talk to
a user, you should probably be using pseudo-tty's.

Cheers,
M.

-- 
  Just put the user directories on a 486 with deadrat7.1 and turn the
  Octane into the afforementioned beer fridge and keep it in your
  office. The lusers won't notice the difference, except that you're
  more cheery during office hours.              -- Pim van Riezen, asr



More information about the Python-list mailing list