OLD | NEW |
(Empty) | |
| 1 diff --git a/third_party/android_testrunner/run_command.py b/third_party/android
_testrunner/run_command.py |
| 2 index d398daa..812037d 100644 |
| 3 --- a/third_party/android_testrunner/run_command.py |
| 4 +++ b/third_party/android_testrunner/run_command.py |
| 5 @@ -80,29 +80,28 @@ def RunOnce(cmd, timeout_time=None, return_output=True, stdi
n_input=None): |
| 6 """ |
| 7 start_time = time.time() |
| 8 so = [] |
| 9 - pid = [] |
| 10 global _abort_on_error, error_occurred |
| 11 error_occurred = False |
| 12 |
| 13 + if return_output: |
| 14 + output_dest = subprocess.PIPE |
| 15 + else: |
| 16 + # None means direct to stdout |
| 17 + output_dest = None |
| 18 + if stdin_input: |
| 19 + stdin_dest = subprocess.PIPE |
| 20 + else: |
| 21 + stdin_dest = None |
| 22 + pipe = subprocess.Popen( |
| 23 + cmd, |
| 24 + executable='/bin/bash', |
| 25 + stdin=stdin_dest, |
| 26 + stdout=output_dest, |
| 27 + stderr=subprocess.STDOUT, |
| 28 + shell=True) |
| 29 + |
| 30 def Run(): |
| 31 global error_occurred |
| 32 - if return_output: |
| 33 - output_dest = subprocess.PIPE |
| 34 - else: |
| 35 - # None means direct to stdout |
| 36 - output_dest = None |
| 37 - if stdin_input: |
| 38 - stdin_dest = subprocess.PIPE |
| 39 - else: |
| 40 - stdin_dest = None |
| 41 - pipe = subprocess.Popen( |
| 42 - cmd, |
| 43 - executable='/bin/bash', |
| 44 - stdin=stdin_dest, |
| 45 - stdout=output_dest, |
| 46 - stderr=subprocess.STDOUT, |
| 47 - shell=True) |
| 48 - pid.append(pipe.pid) |
| 49 try: |
| 50 output = pipe.communicate(input=stdin_input)[0] |
| 51 if output is not None and len(output) > 0: |
| 52 @@ -119,27 +118,17 @@ def RunOnce(cmd, timeout_time=None, return_output=True, st
din_input=None): |
| 53 |
| 54 t = threading.Thread(target=Run) |
| 55 t.start() |
| 56 - |
| 57 - break_loop = False |
| 58 - while not break_loop: |
| 59 - if not t.isAlive(): |
| 60 - break_loop = True |
| 61 - |
| 62 - # Check the timeout |
| 63 - if (not break_loop and timeout_time is not None |
| 64 - and time.time() > start_time + timeout_time): |
| 65 - try: |
| 66 - os.kill(pid[0], signal.SIGKILL) |
| 67 - except OSError: |
| 68 - # process already dead. No action required. |
| 69 - pass |
| 70 - |
| 71 + t.join(timeout_time) |
| 72 + if t.isAlive(): |
| 73 + try: |
| 74 + pipe.kill() |
| 75 + except OSError: |
| 76 + # Can't kill a dead process. |
| 77 + pass |
| 78 + finally: |
| 79 logger.SilentLog("about to raise a timeout for: %s" % cmd) |
| 80 raise errors.WaitForResponseTimedOutError |
| 81 - if not break_loop: |
| 82 - time.sleep(0.1) |
| 83 |
| 84 - t.join() |
| 85 output = "".join(so) |
| 86 if _abort_on_error and error_occurred: |
| 87 raise errors.AbortError(msg=output) |
OLD | NEW |