Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:module': 0.04; '"""': 0.07; 'attribute.': 0.09; 'danny': 0.09; 'deprecated': 0.09; 'output': 0.10; "'-r',": 0.16; 'docs,': 0.16; 'like?': 0.16; 'parallel,': 0.16; 'returncode': 0.16; 'terminate.': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; 'cheers,': 0.18; 'subject:skip:s 10': 0.18; 'cc:no real name:2**0': 0.20; 'seems': 0.20; 'trying': 0.21; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'tue,': 0.23; 'pm,': 0.24; 'aug': 0.24; "i'm": 0.27; 'all,': 0.28; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'threads': 0.30; 'url:library': 0.31; 'chris': 0.32; "what's": 0.33; 'external': 0.35; 'url:python': 0.36; 'data.': 0.36; 'using': 0.37; 'but': 0.37; 'some': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'url:docs': 0.39; 'enough': 0.39; 'more': 0.60; 'your': 0.61; 'waiting': 0.63; '\xe2\x80\x93': 0.65; 'database.': 0.74; '11:48': 0.84; 'sender:addr:chris': 0.84; 'received:209.85.218.46': 0.91; 'received:mail- yi0-f46.google.com': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=VTkXDr83AFrfso86Qg6eX0HRwiXAvbpCE1i1nemmtVE=; b=K2MK5m5Kposz3T85FKnxZeOfbEefOtEhVADTa6vmMHVsgby5SF3Ot4MOX6Z/N0LA9t qm4sIPYL/rK5qHJZ3kQmbTVDst/y97R1fRGL3I7J0yvBCLDaw5lu8fbRg+ZM19++UPuP njutKRHPJVR2SRGGR6OUPIY8va4UrZ9Qnts/o= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: <20110808013500.7c9e30ff44caee0f0bbf988a@johnohagan.com> Date: Tue, 9 Aug 2011 23:53:29 -0700 X-Google-Sender-Auth: oeOC_mxBRnlnRMc4E46As3x-EIQ Subject: Re: subprocess.Popen and thread module From: Chris Rebert To: "Danny Wong (dannwong)" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312959211 news.xs4all.nl 23861 [2001:888:2000:d::a6]:38879 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11098 > On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong) > wrote: >> Hi All, >> =C2=A0 I'm trying to execute some external commands from multiple databa= se. >> I'm using threads and subprocess.Popen ( from docs, all the popen* >> functions are deprecated and I was told to use subprocess.Popen) to >> execute the external commands in parallel, but the commands seems to >> hang. > > What's your Popen() call look like? On Tue, Aug 9, 2011 at 11:48 PM, Danny Wong (dannwong) wrote: > =C2=A0 =C2=A0try: > =C2=A0 =C2=A0 =C2=A0 =C2=A0cmd_output =3D subprocess.Popen(['scm', 'load'= , '--force', '-r', nickname, '-d', directory, project], stdout=3Dsubprocess= .PIPE, stderr=3Dsubprocess.PIPE) > =C2=A0 =C2=A0 =C2=A0 =C2=A0status =3D cmd_output.wait() Er, did you read the warning about Popen.wait() in the docs? (emphasis adde= d): """ Popen.wait() Wait for child process to terminate. Set and return returncode attribut= e. Warning: ***This will deadlock*** when using stdout=3DPIPE and/or stderr=3DPIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that. """ =E2=80=93 http://docs.python.org/library/subprocess.html#subprocess.Popen.w= ait Cheers, Chris