Path: csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!xlned.com!feeder7.xlned.com!news2.euro.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'thread,': 0.03; 'attempting': 0.04; 'received:localnet': 0.05; 'string,': 0.05; 'subject:process': 0.07; 'closed,': 0.09; 'subprocess': 0.09; 'output': 0.10; 'tue,': 0.12; 'wrote:': 0.14; 'case.': 0.15; "'w')": 0.16; 'added:': 0.16; 'did:': 0.16; 'failing,': 0.16; 'input,': 0.16; "isn't.": 0.16; 'received:124.168': 0.16; 'stdout': 0.16; 'subject:discard': 0.16; 'subject:server': 0.16; 'feb': 0.16; 'seems': 0.17; 'fix': 0.20; 'nobody': 0.21; 'sender:addr:gmail.com': 0.22; 'buffer': 0.23; 'header:In-Reply- To:1': 0.23; "wouldn't": 0.25; 'thanks,': 0.26; 'work.': 0.26; 'function': 0.27; 'otherwise,': 0.28; "i'm": 0.28; "can't": 0.28; 'curious': 0.28; 'discard': 0.28; "what's": 0.29; 'server': 0.30; 'file.': 0.31; 'to:addr:python-list': 0.31; 'starting': 0.31; 'skip:o 20': 0.31; 'earlier': 0.31; 'thu,': 0.31; "won't": 0.32; 'up.': 0.33; 'no.': 0.33; 'file': 0.34; 'options': 0.34; 'running': 0.34; '[...]': 0.34; 'there': 0.34; 'header:User- Agent:1': 0.34; 'received:209.85.218': 0.35; 'but': 0.36; 'line,': 0.36; 'thread': 0.36; 'think': 0.37; 'close': 0.37; 'it?': 0.38; 'received:209.85': 0.38; 'received:google.com': 0.38; 'effect': 0.38; 'clear': 0.38; 'fact': 0.38; 'subject:: ': 0.39; 'some': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; "it's": 0.40; 'that.': 0.40; 'header:Message-Id:1': 0.61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:organization:to:subject:date :user-agent:references:in-reply-to:mime-version:content-type :content-transfer-encoding:message-id; bh=6jYuph2uqSC+3ld3Jx2JIvhPWtxGPthpMavqrl0lU/8=; b=ZfqU9Nqq0rvaOBXCgTkRBceVb9hD6BshSlE/nv+/1zPbXXh7t3Rck9HJXII3fjPPhT ZqASLMwj4EkTkBcMDR+Fql6exgpBCDSqE92ANiY+OgWR0SjEPPPG9tW6BvreViBXgvvn zDDU2zG9DdSO0pbfmuu1xjILGqG0A9KfMLmwI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:organization:to:subject:date:user-agent:references :in-reply-to:mime-version:content-type:content-transfer-encoding :message-id; b=Bk3Zzx46wz5bQQTxFuEK25E2PM93+YwzODaMC/t3xTpdYJbvb0RGAJrYfETmTGrFLG twFJJeG7uMOPe2+kMyKuM5wWF15hsSlaY1NnN9B+QAzZrGtfUIQxWbh8dRGVhSQkmpVo XGwvpcCq6G5Crn0vPeE0Z+ZyM+mytTDo99308= Sender: "John O'Hagan" From: "John O'Hagan" Organization: johnohagan.com To: python-list@python.org Subject: Re: Reassign or discard Popen().stdout from a server process Date: Fri, 4 Feb 2011 15:48:55 +0000 User-Agent: KMail/1.13.5 (Linux/2.6.32-2011-01-16-16.13; KDE/4.4.5; i686; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 39 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1296834558 news.xs4all.nl 81479 [::ffff:82.94.164.166]:50893 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55857 On Thu, 3 Feb 2011, Nobody wrote: > On Tue, 01 Feb 2011 08:30:19 +0000, John O'Hagan wrote: > > I can't keep reading because that will block - there won't be any more > > output until I send some input, and I don't want it in any case. > > > > To try to fix this I added: > > > > proc.stdout = os.path.devnull > > > > which has the effect of stopping the server from failing, but I'm not > > convinced it's doing what I think it is. > > It isn't. os.path.devnull is a string, not a file. But even if you did: > > proc.stdout = open(os.path.devnull, 'w') > > that still wouldn't work. As mentioned earlier in the thread, I did in fact use open(), this was a typo, [...] > > Is it possible to re-assign the stdout of a subprocess after it has > > started? > > No. > > > Or just close it? What's the right way to read stdout up to a given > > line, then discard the rest? > > If the server can handle the pipe being closed, go with that. Otherwise, > options include redirecting stdout to a file and running "tail -f" on the > file from within Python, or starting a thread or process whose sole > function is to read and discard the server's output. Thanks, that's all clear now. But I'm still a little curious as to why even unsuccessfully attempting to reassign stdout seems to stop the pipe buffer from filling up. John