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


Groups > comp.lang.python > #77245

Re: Reading from sys.stdin reads the whole file in

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:file': 0.07; 'sys': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'works.': 0.09; 'python': 0.11; 'bug': 0.12; "'r',": 0.16; 'does,': 0.16; 'fine;': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Reading': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'help.': 0.21; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'script.': 0.24; 'looks': 0.24; 'header:X-Complaints-To:1': 0.27; 'chris': 0.29; 'url:bugs': 0.29; "doesn't": 0.30; '(although': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'writes:': 0.31; 'run': 0.32; 'url:python': 0.33; 'subject:the': 0.34; 'subject:from': 0.34; 'could': 0.34; 'but': 0.35; 'url:org': 0.36; 'message-id:@gmail.com': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'everywhere.': 0.84; 'received:89': 0.85
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Akira Li <4kir4.1i@gmail.com>
Subject Re: Reading from sys.stdin reads the whole file in
Date Fri, 29 Aug 2014 04:02:38 +0400
References <53fd6a48$0$11111$c3e8da3@news.astraweb.com> <87mwaqxzyn.fsf@elektro.pacujo.net> <53fd7cab$0$11111$c3e8da3@news.astraweb.com> <CAPTjJmoJ4oYtYuHKzV-knPWYvAQ-XK_VN2cj2Vge3hHzjg-DnA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain
X-Gmane-NNTP-Posting-Host 89.169.229.68
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)
Cancel-Lock sha1:Qgj5VVNYPz7t6tE/8megyyC6400=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13590.1409270573.18130.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1409270573 news.xs4all.nl 2852 [2001:888:2000:d::a6]:46422
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:77245

Show key headers only | View raw


Chris Angelico <rosuav@gmail.com> writes:

> On Wed, Aug 27, 2014 at 4:37 PM, Steven D'Aprano <steve@pearwood.info> wrote:
>> On Wed, 27 Aug 2014 08:29:20 +0300, Marko Rauhamaa wrote:
>>
>>> Try flushing after each print.
>>
>> Doesn't help.
>
> It does, but insufficiently. If slurp.py is run under Py3, it works
> fine; or take Naoki's suggestion (although without the parens):
>
> import sys
> import time
>
> for line in iter(sys.stdin.readline, ''):
>         print "Time of input:", time.ctime(), line
>         sys.stdin.flush()
>         sys.stdout.flush()
>
> Then it works.
>
> ChrisA

It looks like this bug http://bugs.python.org/issue3907

`python -u out.py | python -u slurp.py`  could be used to avoid .flush()
calls everywhere.

Or reassign `sys.stdin = io.open(sys.stdin.fileno(), 'r', 1)` inside the
script.

http://stackoverflow.com/questions/107705/python-output-buffering


--
Akira

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


Thread

Reading from sys.stdin reads the whole file in Steven D'Aprano <steve@pearwood.info> - 2014-08-27 05:19 +0000
  Re: Reading from sys.stdin reads the whole file in Marko Rauhamaa <marko@pacujo.net> - 2014-08-27 08:29 +0300
    Re: Reading from sys.stdin reads the whole file in Marko Rauhamaa <marko@pacujo.net> - 2014-08-27 08:31 +0300
    Re: Reading from sys.stdin reads the whole file in Steven D'Aprano <steve@pearwood.info> - 2014-08-27 06:37 +0000
      Re: Reading from sys.stdin reads the whole file in Chris Angelico <rosuav@gmail.com> - 2014-08-27 16:45 +1000
      Re: Reading from sys.stdin reads the whole file in Akira Li <4kir4.1i@gmail.com> - 2014-08-29 04:02 +0400
  Re: Reading from sys.stdin reads the whole file in Chris Angelico <rosuav@gmail.com> - 2014-08-27 16:02 +1000
  Re: Reading from sys.stdin reads the whole file in Peter Otten <__peter__@web.de> - 2014-08-27 09:42 +0200
    Re: Reading from sys.stdin reads the whole file in Marko Rauhamaa <marko@pacujo.net> - 2014-08-27 11:39 +0300
      Re: Reading from sys.stdin reads the whole file in Peter Otten <__peter__@web.de> - 2014-08-27 11:31 +0200

csiph-web