Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79280

Re: Flush stdin

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Flush stdin
Date 2014-10-18 18:35 -0400
References <pan.2014.10.18.16.55.19.164000@nowhere.invalid> <20141018210111.GA33086@cskk.homeip.net>
Newsgroups comp.lang.python
Message-ID <mailman.14975.1413671742.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 10/18/2014 5:01 PM, Cameron Simpson wrote:
> On 18Oct2014 17:55, Nobody <nobody@nowhere.invalid> wrote:
>> On Fri, 17 Oct 2014 12:38:54 +0100, Empty Account wrote:
>>> I am using netcat to listen to a port and python to read stdin and print
>>> to the console.
>>>
>>> nc -l 2003 | python print_metrics.py
>>>
>>> sys.stdin.flush() doesn’t seem to flush stdin,
>>
>> You can't "flush" an input stream.

> Sure you can.

You are collectively confusing three different meaning of 'flush'. 
Python and its docs are the best authority on what python can and cannot 
do.  One can "call .flush() on an imput stream" (meaning 1).

 >>> import sys
 >>> sys.stdin.flush()
 >>>

However, one cannot "empty the steam buffer by calling .flush()" 
(meaning 2).

" class IOBase
...
flush()
     Flush the write buffers of the stream if applicable. This does 
nothing for read-only and non-blocking streams."

> Most streams are read through an API which buffers. That
> buffer can be discarded.

But one can "empty and discard the buffer" (meaning 3) with
stream.read()

And, of course, an 'input stream' 'down here' is an 'output stream' 'up 
there, where ever' and one can 'flush' pending output into the stream so 
that it can be read here.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Flush stdin Empty Account <emptya45@gmail.com> - 2014-10-17 12:38 +0100
  Re: Flush stdin Nobody <nobody@nowhere.invalid> - 2014-10-18 17:55 +0100
    Re: Flush stdin Tim Chase <python.list@tim.thechases.com> - 2014-10-18 12:32 -0500
      Re: Flush stdin Nobody <nobody@nowhere.invalid> - 2014-10-19 02:11 +0100
        Re: Flush stdin Dan Stromberg <drsalists@gmail.com> - 2014-10-18 18:34 -0700
        Re: Flush stdin Dan Stromberg <drsalists@gmail.com> - 2014-10-18 18:42 -0700
          Re: Flush stdin Nobody <nobody@nowhere.invalid> - 2014-10-22 03:49 +0100
            Re: Flush stdin Dan Stromberg <drsalists@gmail.com> - 2014-10-21 20:11 -0700
    Re: Flush stdin MRAB <python@mrabarnett.plus.com> - 2014-10-18 18:55 +0100
    Re: Flush stdin Cameron Simpson <cs@zip.com.au> - 2014-10-19 08:01 +1100
    Re: Flush stdin Terry Reedy <tjreedy@udel.edu> - 2014-10-18 18:35 -0400

csiph-web