Chromium Code Reviews| Index: scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py |
| diff --git a/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py b/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py |
| index af8e3e1d11757601ad6a5f8501c979cebddf8142..380df88e98c1b464e05fb3165f1e1b7b5af4d182 100644 |
| --- a/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py |
| +++ b/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py |
| @@ -5,6 +5,7 @@ |
| import argparse |
| import errno |
| +import multiprocessing |
| import os |
| import signal |
| import subprocess |
| @@ -49,6 +50,24 @@ def is_running_posix(pid): |
| return True |
| +def waitpid_for_win(pid): |
| + """Return exception if raised in os.waitpid, or None. |
| + |
| + Args: |
| + pid(int): pid of process which this function checks |
| + whether it is running or not. |
| + |
| + Returns: |
| + Exception: if something raised in os.waitpid. |
|
tikuta
2016/10/21 02:35:04
nit: I prefer to use 'If' here or use 'otherwise'
Yoshisato Yanagisawa
2016/10/21 02:38:15
good catch.
|
| + None: Otherwise. |
| + """ |
| + try: |
| + os.waitpid(pid, 0) |
| + except Exception as e: |
| + return e |
| + return None |
| + |
| + |
| class NotDiedError(Exception): |
| def __str__(self): |
| return "NotDiedError" |
| @@ -76,13 +95,19 @@ def wait_termination(pid): |
| print('SIGINT has been sent to process %d. ' |
| 'Going to wait for the process finishes.' % pid) |
| if os.name == 'nt': |
| + pool = multiprocessing.Pool(1) |
| + res = pool.apply_async(waitpid_for_win) |
| try: |
| - os.waitpid(pid, 0) |
| - except OSError as e: |
| - if e.errno == errno.ECHILD: |
| + e = res.get(10) |
| + except multiprocessing.TimeoutError: |
| + print('process %d running more than 10 seconds' % pid) |
| + raise NotDiedError() |
| + if e is None: |
| + return |
| + if isinstance(e, OSError) and e.errno == errno.ECHILD: |
| print('process %d died before waitpitd' % pid) |
| return |
| - raise e |
| + raise e |
| else: |
| for _ in xrange(10): |
| time.sleep(1) |