From 2ca6669f8e71dd06390b808d391edec2c746a43d Mon Sep 17 00:00:00 2001 From: navid Date: Fri, 5 Oct 2007 09:54:32 +0000 Subject: fixed buggy new process spawning code git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@415 ef72aa8b-4018-0410-8976-d6e080ef94d8 --- src/lib/sos/helpers.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/lib') diff --git a/src/lib/sos/helpers.py b/src/lib/sos/helpers.py index 7f2e335d..61ce8487 100755 --- a/src/lib/sos/helpers.py +++ b/src/lib/sos/helpers.py @@ -81,24 +81,28 @@ def sosGetCommandOutput(command, timeout = 300): if pid: # we are the parent os.close(w) # use os.close() to close a file descriptor + oldr = r r = os.fdopen(r) # turn r into a file object stime=time() txt = "" + sts = -1 while True: # read output from pipe - txt = txt + r.read() + ready = select.select([oldr],[],[],1) + if len(ready[0]): + txt = txt + r.read() # is child still running ? try: os.waitpid(pid, os.WNOHANG) - except: break - # has 5 secs timeout passed ? + except: + # not running, make sure the child process gets cleaned up + try: sts = os.waitpid(pid, 0)[1] + except: pass + break + # has timeout passed ? if time() - stime > timeout: soslog.log(logging.VERBOSE, 'killing hung child with pid %s after %d seconds (command was "%s")' % (pid,timeout,command) ) os.kill(pid, signal.SIGKILL) break - sleep(0.1) - # make sure the child process gets cleaned up - try: sts = os.waitpid(pid, 0)[1] - except: sts = -1 if txt[-1:] == '\n': txt = txt[:-1] return (sts, txt, time()-stime) else: -- cgit