diff options
author | navid <navid@ef72aa8b-4018-0410-8976-d6e080ef94d8> | 2007-10-05 09:54:32 +0000 |
---|---|---|
committer | navid <navid@ef72aa8b-4018-0410-8976-d6e080ef94d8> | 2007-10-05 09:54:32 +0000 |
commit | 2ca6669f8e71dd06390b808d391edec2c746a43d (patch) | |
tree | fd28f44dfbbb38f37fb4eed10a6ca79ff7510584 /src/lib | |
parent | 8e1596469a45db9516fd6cb44e5ae286be560a05 (diff) | |
download | sos-2ca6669f8e71dd06390b808d391edec2c746a43d.tar.gz |
fixed buggy new process spawning code
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@415 ef72aa8b-4018-0410-8976-d6e080ef94d8
Diffstat (limited to 'src/lib')
-rwxr-xr-x | src/lib/sos/helpers.py | 18 |
1 files changed, 11 insertions, 7 deletions
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: |