Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'exit': 0.07; 'finished,': 0.07; 'python': 0.09; 'anymore.': 0.09; 'observation': 0.09; 'threads.': 0.09; 'cc:addr:python-list': 0.10; 'anyway': 0.11; 'subject:not': 0.11; 'thread': 0.11; 'end-of-file': 0.16; 'it..': 0.16; 'processes.': 0.16; 'subprocess': 0.16; 'differ': 0.17; 'written': 0.20; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'external': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'leave': 0.26; 'instead.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'options': 0.27; 'correct': 0.28; 'run': 0.28; 'things,': 0.29; 'probably': 0.29; "i'm": 0.29; 'problem.': 0.32; 'launch': 0.32; 'could': 0.32; 'monitor': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; "i'll": 0.36; 'should': 0.36; 'possible': 0.37; 'two': 0.37; 'quite': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'sure': 0.38; 'shows': 0.38; 'page': 0.38; 'header:Received:5': 0.40; 'your': 0.60; 'most': 0.61; "you'll": 0.62; 'between': 0.63; 'show': 0.63; 'else.': 0.65; 'sounds': 0.71; '(they': 0.84; 'reap': 0.84; 'anywhere,': 0.93; 'processes,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=KvJx3k7Woz515jdZTjgn0suImYz2bPXU2hJ6TGLZdDY=; b=koYFR+KWtRBxEDjDCgdOHxnyb1roOTYJMs1RHTp/gcy6FwuEZapyq+ZYRaKSs2/NAZ YJyioAJjRpsUXXZciaKHvOj1le2VcgnBrTtS8PwMOR8mBMFVY6IGj5xZYKlSOJOiseHE Loh6aSAH/5Gd9idVIl15R4bZmInnBHC1AhEvtpboXh5ELebiC5Ozcs2eJoLEJogXU+oh GdvQQkStuHA51crMe3esPaSRGYuIV7FcFqy59p9YMO5g0+yw0bC7lLuxxG/gOP4ucIDX K1B9NRNKT33+78GLotc5VHgBUY+OIXTe2pBAjJ/jUDG4j2EZkVFu7pYOHJpNRFSYBH+L zchQ== MIME-Version: 1.0 In-Reply-To: <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> References: <0b598d7f-7137-47cc-8eed-80ab450536c5@googlegroups.com> <0405db16-6a4c-4189-a32c-2311d45eead3@googlegroups.com> <28ih585cvob222k24v7ccfapgvav7nfgur@invalid.netcom.com> <5059c765$0$6952$e4fe514c@news2.news.xs4all.nl> Date: Wed, 19 Sep 2012 17:34:58 +0100 Subject: Re: subprocess call is not waiting. From: andrea crotti To: Hans Mulder Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org 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: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348072500 news.xs4all.nl 6922 [2001:888:2000:d::a6]:32964 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29506 2012/9/19 Hans Mulder : > Yes: using "top" is an observation problem. > > "Top", as the name suggests, shows only the most active processes. Sure but "ls -lR /" is a very active process if you try to run it.. Anyway as written below I don't need this anymore. > > 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, > Well there is a process which has to do two things, monitor periodically some external conditions (filesystem / db), and launch a process that can take very long time. So I can't put a wait anywhere, or I'll stop everything else. But at the same time I need to know when the process is finished, which I could do but without a wait might get hacky. So I'm quite sure I just need to run the subprocess in a subthread unless I'm missing something obvious..