Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'discard': 0.07; 'sys': 0.07; 'read-only': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'api': 0.11; 'python': 0.11; 'jan': 0.12; '(meaning': 0.16; 'discarded.': 0.16; 'flush': 0.16; 'imput': 0.16; 'non-blocking': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'simpson': 0.16; 'wrote:': 0.18; 'do.': 0.18; '>>>': 0.22; 'input': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'pending': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; '+0100,': 0.31; 'class': 0.32; 'fri,': 0.33; 'there,': 0.34; "can't": 0.35; 'but': 0.35; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'authority': 0.60; 'most': 0.60; 'different': 0.65; 'account': 0.65; 'nobody': 0.68; 'applicable.': 0.84; 'confusing': 0.84; 'received:fios.verizon.net': 0.84; 'streams': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Flush stdin Date: Sat, 18 Oct 2014 18:35:17 -0400 References: <20141018210111.GA33086@cskk.homeip.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: pool-108-16-203-145.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <20141018210111.GA33086@cskk.homeip.net> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413671742 news.xs4all.nl 2900 [2001:888:2000:d::a6]:57560 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79280 On 10/18/2014 5:01 PM, Cameron Simpson wrote: > On 18Oct2014 17:55, Nobody 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 pr= int >>> to the console. >>> >>> nc -l 2003 | python print_metrics.py >>> >>> sys.stdin.flush() doesn=E2=80=99t seem to flush stdin, >> >> You can't "flush" an input stream. > Sure you can. You are collectively confusing three different meaning of 'flush'.=20 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()"=20 (meaning 2). " class IOBase =2E.. flush() Flush the write buffers of the stream if applicable. This does=20 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=20 there, where ever' and one can 'flush' pending output into the stream so = that it can be read here. --=20 Terry Jan Reedy