subprocess hangs on reading stdout

Minesh Patel minesh at
Thu Oct 15 07:10:28 CEST 2009

> Any ideas? comments on code welcome also.

Here's something that I would probably do, there may be better ways.
This only works on python2.6 for the terminate() method.

import signal
import subprocess

def timeout_handler(signum, frame):
    print "About to kill process"

for machine_name in self.alive:
    cmd = ["/bin/remsh", machine_name, 'ps -flu %s' % uid]
    signal.signal(signal.SIGALRM, timeout_handler)
    p = subprocess.Popen(cmd,stdout=subprocess.PIPE)
    (stdout, stderr) = p.communicate()
    if stdout:
       print stdout
    elif stderr:
       print stderr


More information about the Python-list mailing list