subprocess hangs on reading stdout
Tim Arnold
tim.arnold at sas.com
Thu Oct 15 12:39:34 EDT 2009
"Minesh Patel" <minesh at gmail.com> wrote in message
news:mailman.1408.1255583431.2807.python-list at python.org...
> >
>> 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"
> p.terminate()
>
> for machine_name in self.alive:
> cmd = ["/bin/remsh", machine_name, 'ps -flu %s' % uid]
> signal.signal(signal.SIGALRM, timeout_handler)
> signal.alarm(1)
> p = subprocess.Popen(cmd,stdout=subprocess.PIPE)
> (stdout, stderr) = p.communicate()
> signal.alarm(0)
> if stdout:
> print stdout
> elif stderr:
> print stderr
>
>
>
> --
> Thanks,
> --Minesh
Hi Minesh,
Looks like I need to learn about signals--that code looks nice. I'm using
python2.6.
thanks,
--Tim Arnold
More information about the Python-list
mailing list