Delays getting data on sys.stdin.readline() ?

Fredrik Lundh fredrik at pythonware.com
Sun Nov 20 22:49:22 CET 2005


Christian Convey wrote:

> So here's what I don't get: If "producer" was retaining its output for
> a while for the sake of efficiency, I would expect to see that effect
> when I just run "producer" on the command line. That is, I would
> expect the console to not show any output from "producer" until
> "producer" terminates.  But instead, I see the output immediately. So
> why, when I pipe the output to "consumer", doesn't "consumer" get
> access to that data as its produced unless "consumer" is explicitely
> calling sys.stdout.flush().
>
> Any thoughts?

your terminal is not a pipe.

$ man stdout

...

CONSIDERATIONS
     The stream stderr is unbuffered. The stream stdout is line-buffered when
     it points to a terminal. Partial lines will not appear until fflush(3) or
     exit(3) is called, or a newline is printed. This can produce unexpected
     results, especially with debugging output.  The buffering mode of the
     standard streams (or any other stream) can be changed using the setbuf(3)
     or setvbuf(3) call.  Note that in case stdin is associated with a termi­
     nal, there may also be input buffering in the terminal driver, entirely
     unrelated to stdio buffering.  (Indeed, normally terminal input is line
     buffered in the kernel.)  This kernel input handling can be modified
     using calls like tcsetattr(3); see also stty(1), and termios(3).

...

</F>






More information about the Python-list mailing list