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: 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> 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 Chris Angelico writes: > On Wed, Aug 27, 2014 at 4:37 PM, Steven D'Aprano 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