diff options
author | Michael E Brown <mebrown@michaels-house.net> | 2008-01-29 23:48:50 -0600 |
---|---|---|
committer | Michael E Brown <mebrown@michaels-house.net> | 2008-01-29 23:48:50 -0600 |
commit | 5ff9b7b2da07756df55e56a0ef58e21b66d6ee2b (patch) | |
tree | 52ee54c1df0ab4420690ffad02b482fc4bd09e6c /py/mock/util.py | |
parent | f1f47ae2bb7770c6ed072f779763c275a18f9828 (diff) | |
parent | 56957fc4b42272bf900daf00649e1acbf94378f4 (diff) | |
download | mock-5ff9b7b2da07756df55e56a0ef58e21b66d6ee2b.tar.gz mock-5ff9b7b2da07756df55e56a0ef58e21b66d6ee2b.tar.xz mock-5ff9b7b2da07756df55e56a0ef58e21b66d6ee2b.zip |
Merge ssh://mock/var/ftp/pub/Applications/git/mock
* ssh://mock/var/ftp/pub/Applications/git/mock:
updates to mock.util.do(): 1) nonblocking read, 2) dont leave zombies (waitpid).
we now run /etc/profile, so no need to manually do ccache stuff.
use makeChrootPath() functionality rather than obscure string interpolation
Diffstat (limited to 'py/mock/util.py')
-rw-r--r-- | py/mock/util.py | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/py/mock/util.py b/py/mock/util.py index 65cc995..a0a6b65 100644 --- a/py/mock/util.py +++ b/py/mock/util.py @@ -224,6 +224,13 @@ def condPersonality(per=None): def logOutput(fds, logger, returnOutput=1, start=0, timeout=0): output="" done = 0 + + # set all fds to nonblocking + for fd in fds: + flags = fcntl.fcntl(fd, fcntl.F_GETFL) + if not fd.closed: + fcntl.fcntl(fd, fcntl.F_SETFL, flags| os.O_NONBLOCK) + while not done: if (time.time() - start)>timeout and timeout!=0: done = 1 @@ -231,15 +238,19 @@ def logOutput(fds, logger, returnOutput=1, start=0, timeout=0): i_rdy,o_rdy,e_rdy = select.select(fds,[],[],1) for s in i_rdy: - # this isnt perfect as a whole line of input may not be - # ready, but should be "good enough" for now - line = s.readline() - if line == "": + # slurp as much input as is ready + input = s.read() + if input == "": done = 1 break - logger.debug(chomp(line)) + if logger is not None: + for line in input.split("\n"): + if line == '': continue + logger.debug(chomp(line)) + for h in logger.handlers: + h.flush() if returnOutput: - output += line + output += input return output # logger = @@ -275,17 +286,26 @@ def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True except: # kill children if they arent done if child is not None and child.returncode is None: - os.kill(-child.pid, 15) - os.kill(-child.pid, 9) + os.killpg(child.pid, 9) + try: + if child is not None: + os.waitpid(child.pid, 0) + except: + pass raise # wait until child is done, kill it if it passes timeout + niceExit=1 while child.poll() is None: if (time.time() - start)>timeout and timeout!=0: - os.kill(-child.pid, 15) - os.kill(-child.pid, 9) - raise commandTimeoutExpired, ("Timeout(%s) expired for command:\n # %s\n%s" % (command, output)) - + niceExit=0 + os.killpg(child.pid, 15) + if (time.time() - start)>(timeout+1) and timeout!=0: + niceExit=0 + os.killpg(child.pid, 9) + + if not niceExit: + raise commandTimeoutExpired, ("Timeout(%s) expired for command:\n # %s\n%s" % (timeout, cmd, output)) if raiseExc and child.returncode: if returnOutput: |