Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'reject': 0.05; 'exit': 0.07; 'finished,': 0.07; 'problem?': 0.07; 'run,': 0.07; 'python': 0.09; 'blocked': 0.09; 'observation': 0.09; 'threads.': 0.09; 'anyway': 0.11; 'subject:not': 0.11; 'thread': 0.11; 'end-of- file': 0.16; 'proc': 0.16; 'processes.': 0.16; 'soap,': 0.16; 'wrote:': 0.17; 'differ': 0.17; 'shell': 0.18; 'cheers,': 0.23; 'this:': 0.23; 'command': 0.24; 'tried': 0.25; 'header:In-Reply- To:1': 0.25; 'leave': 0.26; 'instead.': 0.27; 'options': 0.27; 'correct': 0.28; 'run': 0.28; '"the': 0.29; 'probably': 0.29; 'url :non-standard http port': 0.30; 'problem.': 0.32; 'running': 0.32; 'defense': 0.33; 'scroll': 0.33; 'up!': 0.33; 'wednesday': 0.33; 'to:addr:python-list': 0.33; 'massive': 0.35; 'really': 0.36; 'should': 0.36; 'possible': 0.37; 'why': 0.37; 'quite': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'nothing': 0.38; 'shows': 0.38; 'page': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'most': 0.61; 'charset:windows-1256': 0.61; "you'll": 0.62; 'header:Message- Id:1': 0.62; 'between': 0.63; 'show': 0.63; 'sounds': 0.71; 'received:204': 0.72; '100%': 0.76; '(they': 0.84; 'andrea': 0.84; 'everything.': 0.84; 'reap': 0.84; 'received:66.118': 0.84; 'running,': 0.84; 'dennis': 0.91; 'processes,': 0.93 X-Spam-Status: No, score=-2.1 required=5.0 X-Spam-Level: From: Gene Heskett To: python-list@python.org Subject: Re: subprocess call is not waiting. Date: Wed, 19 Sep 2012 11:57:47 -0400 References: <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> In-Reply-To: <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> MIME-Version: 1.0 Content-Type: Text/Plain; charset="windows-1256" Content-Transfer-Encoding: 7bit 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: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348070282 news.xs4all.nl 6949 [2001:888:2000:d::a6]:40354 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29503 On Wednesday 19 September 2012 11:56:44 Hans Mulder did opine: > On 19/09/12 12:26:30, andrea crotti wrote: > > 2012/9/18 Dennis Lee Bieber : > >> Unless you have a really massive result set from that "ls", > >> that > >> > >> command probably ran so fast that it is blocked waiting for someone > >> to read the PIPE. > > > > I tried also with "ls -lR /" and that definitively takes a while to > > run, when I do this: > > > > proc = subprocess.Popen(['ls', '-lR', '/'], stdout=subprocess.PIPE, > > stderr=subprocess.PIPE) > > > > nothing is running, only when I actually do > > proc.communicate() > > > > I see the process running in top.. > > Is it still an observation problem? > > Yes: using "top" is an observation problem. > > "Top", as the name suggests, shows only the most active processes. > Which is why I run htop in a shell 100% of the time. With htop, you can scroll down and see everything. > It's quite possible that your 'ls' process is not active, because > it's waiting for your Python process to read some data from the pipe. > > Try using "ps" instead. Look in thte man page for the correct > options (they differ between platforms). The default options do > not show all processes, so they may not show the process you're > looking for. > > > Anyway I also need to know when the process is over while waiting, so > > probably a thread is the only way.. > > This sounds confused. > > You don't need threads. When 'ls' finishes, you'll read end-of-file > on the proc.stdout pipe. You should then call proc.wait() to reap > its exit status (if you don't, you'll leave a zombie process). > Since the process has already finished, the proc.wait() call will > not actually do any waiting. > > > Hope this helps, > > -- HansM Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: is up! To know Edina is to reject it. -- Dudley Riggs, "The Year the Grinch Stole the Election"