How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?

Chris Seberino cseberino at gmail.com
Thu Jun 10 11:40:03 EDT 2010


On Jun 10, 6:52 am, Nobody <nob... at nowhere.com> wrote:
> Without the p1.stdout.close(), if the reader (grep) terminates before
> consuming all of its input, the writer (ls) won't terminate so long as
> Python retains the descriptor corresponding to p1.stdout. In this
> situation, the p1.wait() will deadlock.
>
> The communicate() method wait()s for the process to terminate. Other
> processes need to be wait()ed on explicitly, otherwise you end up with
> "zombies" (labelled "<defunct>" in the output from "ps").

You are obviously very wise on such things.  I'm curious if this
deadlock issue is a rare event since I'm grep (hopefully) would rarely
terminate before consuming all its input.

Even if zombies are created, they will eventually get dealt with my OS
w/o any user intervention needed right?

I'm just trying to verify the naive solution of not worrying about
these deadlock will still be ok and handled adequately by os. :)

cs



More information about the Python-list mailing list