| 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 bfe97d81c9b55bf1b895a97ad565957f9d21e63d..c0d245960be3d70e35bb1799105699d2200dcfbf 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.
|
| + None: otherwise.
|
| + """
|
| + try:
|
| + os.waitpid(pid, 0)
|
| + except Exception as e:
|
| + return e
|
| + return None
|
| +
|
| +
|
| class NotDiedError(Exception):
|
| def __str__(self):
|
| return "NotDiedError"
|
| @@ -79,13 +98,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:
|
| - print('process %d died before waitpitd' % pid)
|
| - return
|
| - raise e
|
| + 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
|
| else:
|
| for _ in xrange(10):
|
| time.sleep(1)
|
|
|