Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'test,': 0.07; 'received:internal': 0.09; 'subject:command': 0.09; 'itself.': 0.14; 'windows': 0.15; '23,': 0.16; 'fancy': 0.16; 'gained': 0.16; 'iterating': 0.16; 'iteration': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:messagingengine.com': 0.16; 'subject:program': 0.16; 'surprising': 0.16; 'wrote:': 0.18; "python's": 0.19; 'code,': 0.22; 'memory': 0.22; 'aug': 0.22; 'print': 0.22; 'either.': 0.24; 'looks': 0.24; 'header:In-Reply- To:1': 0.27; "doesn't": 0.30; 'lines': 0.31; '"")': 0.31; 'once,': 0.31; 'file': 0.32; "we're": 0.32; 'linux': 0.33; 'fri,': 0.33; 'there,': 0.34; 'subject:the': 0.34; 'problem': 0.35; 'received:66': 0.35; 'but': 0.35; 'there': 0.35; 'returning': 0.36; 'received:10': 0.37; 'clear': 0.37; 'performance': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'read': 0.60; 'from:no real name:2**0': 0.61; 'header:Message-Id:1': 0.63; 'confirm': 0.64; 'more': 0.64; 'between': 0.67; 'believe': 0.68; 'benefit': 0.68; 'led': 0.72; 'otten': 0.84; '2013,': 0.91; 'system:': 0.91 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.us; h= message-id:from:to:mime-version:content-transfer-encoding :content-type:in-reply-to:references:subject:date; s=mesmtp; bh= 47b8jun/X9AI4tiG/GfV4zv0TQ8=; b=CcKpWI0elu3WByrWCGJpzhvqWKY2g5CQ ILdN9sTDFKDgk+7KQ7k5SO7lcx9fkXtEyRzncnbE/3tMuls/6Ote+qdTE++IIKls u7HzVrVTf5Il/XJgCz8DKO/BihoquOIjufkDyWcp2LhAHM9OeVTNxaB42vZ21ITg 5VTiMhCZPlg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=47b8jun/X9AI4tiG/GfV4zv0TQ8=; b=fVT g+BSOcKk6xM0/WJQdjPQ6+16tsmougTp6X65qFmO2aVz9VROwxeIPakxXG4Ytqhu ZVwA9uGXDBbhFcqhoA3Uk8WC+CpsCG4Y3svdPw4JIHkzznwwZDfJErd4WvZIMn2A tHVNqb0rHwqISbzyQcOOEdDzBZLymCI44NXrufH8= X-Sasl-Enc: RcS0cIrorMurAifGpSVhP/Gjq26Sy+hN6p+VO8JIIc7W 1377273854 From: random832@fastmail.us To: python-list@python.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Mailer: MessagingEngine.com Webmail Interface - ajax-d009844e In-Reply-To: References: <5215a6cf$0$6512$c3e8da3$5496439d@news.astraweb.com> Subject: Re: Running a command line program and reading the result as it runs Date: Fri, 23 Aug 2013 12:04:14 -0400 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377273859 news.xs4all.nl 15919 [2001:888:2000:d::a6]:35587 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52899 On Fri, Aug 23, 2013, at 7:14, Peter Otten wrote: > The following works on my linux system: > > instream = iter(p.stdout.readline, "") > > for line in instream: > print line.rstrip() > > I don't have Windows available to test, but if it works there, too, the > problem is the internal buffer used by Python's implementation of file > iteration rather than the OS. I can confirm this on Windows. Doesn't this surprising difference between for line in iter(f.readline,'') vs for line in f violate TOOWTDI? We're led to believe from the documentation that iterating over a file does _not_ read lines into memory before returning them. It's not clear to me what performance benefit can be gained from waiting when there is no more data available, either. I don't understand how it's even happening - from looking at the code, it looks like next() just calls readline() once, no fancy buffering specific to itself.