'ps -A' command freezes Popen3

G

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()

Thanks

B.
 
T

Thomas Guettler

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.

HTH,
Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top