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 <wlfr...@ix.netcom.com>: > >> 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: <http://coyoteden.dyndns-free.com:85/gene> is up! To know Edina is to reject it. -- Dudley Riggs, "The Year the Grinch Stole the Election" -- http://mail.python.org/mailman/listinfo/python-list