Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.04; "'')": 0.07; 'reason,': 0.07; 'instance.': 0.09; 'stderr': 0.09; 'subject:files': 0.09; 'subtle': 0.09; 'threads.': 0.09; "('',": 0.16; 'called,': 0.16; 'deadlock': 0.16; 'pipes': 0.16; 'poll': 0.16; 'processes.': 0.16; 'subprocess': 0.16; 'ugly.': 0.16; 'wrote:': 0.17; 'accepting': 0.18; 'input': 0.18; 'sender:addr:gmail.com': 0.18; 'bit': 0.21; 'this:': 0.23; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'separate': 0.27; 'wonder': 0.27; '>>>>': 0.29; 'parent': 0.29; 'subject:size': 0.29; 'writes:': 0.29; 'could': 0.32; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'or,': 0.34; 'nov': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'two': 0.37; 'communicate': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'subject:-': 0.40; 'end': 0.40; 'received:117': 0.75; 'andrea': 0.84; 'thing,': 0.84; 'to:name:python': 0.84; 'subject:limited': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; bh=pT/NhZCBUYPfRuepvBPx5fScSL895z9/6vlTAd3Qc2w=; b=xd7QRg1mgbtMzAWfqlmQU5UVAfJM7p1KIMcmzs9mIHgQCLNwxvSqQhPS6TQORp1TaR /rS296ReOJ5YmAGNEbc7CGqnAgCtQNZuSSK1JveA8fi+PJQD25HFM1jcC7SikAKFhThM B7dAnY2D5Sduy8V7mYGHTYj9IiFuZQu/Kh3dvdJuKORCxsXZLVpjcc1oKGQcHPXhimGH 9IpvHA7g6t52HEalqiF59xv2uNTxiPTBetHl5InhJRA/pAqkeK4i54xCwju1VegfqNqX L0Jds25g7ClMF3l+LqDAjYWbcZ2M3FivG3xDr9/wDrNA2a9LPvc6zuqwzsUmO+cqHPSG ngPg== Sender: Kushal Kumaran From: Kushal Kumaran To: Python Subject: Re: creating size-limited tar files In-Reply-To: References: <509ab0fa$0$6636$9b4e6d93@newsspool2.arcor-online.net> <509AD812.2060605@gmail.com> User-Agent: Notmuch/0.14 (http://notmuchmail.org) Emacs/24.1.1 (x86_64-pc-linux-gnu) Date: Wed, 14 Nov 2012 11:35:04 +0530 MIME-Version: 1.0 Content-Type: text/plain 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352873114 news.xs4all.nl 6885 [2001:888:2000:d::a6]:59502 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33304 Ian Kelly writes: > On Tue, Nov 13, 2012 at 3:31 AM, andrea crotti > wrote: >> but it's a bit ugly. I wonder if I can use the subprocess PIPEs to do >> the same thing, is it going to be as fast and work in the same way?? > > It'll look something like this: > >>>> p1 = subprocess.Popen(cmd1, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) >>>> p2 = subprocess.Popen(cmd2, shell=True, stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) >>>> p1.communicate() > ('', '') >>>> p2.communicate() > ('', '') >>>> p1.wait() > 0 >>>> p2.wait() > 0 > > Note that there's a subtle potential for deadlock here. During the > p1.communicate() call, if the p2 output buffer fills up, then it will > stop accepting input from p1 until p2.communicate() can be called, and > then if that buffer also fills up, p1 will hang. Additionally, if p2 > needs to wait on the parent process for some reason, then you end up > effectively serializing the two processes. > > Solution would be to poll all the open-ended pipes in a select() loop > instead of using communicate(), or perhaps make the two communicate > calls simultaneously in separate threads. Or, you could just change the p1's stderr to an io.BytesIO instance. Then call p2.communicate *first*. -- regards, kushal