'ps -A' command freezes Popen3

Thomas Guettler guettli at thomas-guettler.de
Wed Aug 31 16:52:41 CEST 2005

Am Wed, 31 Aug 2005 07:12:49 -0700 schrieb gao_bolin:

> Does anybody know why the following lines would freeze python [2.4.1 on
> Linux]:
> import popen2
> a = popen2.Popen3('ps -A')
> a.wait()

Because "ps -A" produces a lot of output to stdout, so that
it blocks. It blocks until you read from the stdout of the subprocess.
If you don't read, it will wait forever. You can redirect the output to a
file "ps -A > /tmp/example". This won't block. Or you use the module
select if you are in a unix environment.


Thomas Güttler, http://www.thomas-guettler.de/

More information about the Python-list mailing list