From 8e5718f1000c31b86e3f54e6edaac172c697a49a Mon Sep 17 00:00:00 2001 From: "bulach@chromium.org" Date: Mon, 9 Dec 2013 12:55:22 +0000 Subject: [PATCH] Android: kill leftover webpagereplay servers. Some bots downstream ended up with hundreds of instances. Kill them all before start running the tests. BUG=326540 Review URL: https://codereview.chromium.org/105733013 git-svn-id: http://src.chromium.org/svn/trunk/src/build@239479 4ff67af0-8c30-449e-8e8b-ad334ec8d88c --- android/pylib/utils/test_environment.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/android/pylib/utils/test_environment.py b/android/pylib/utils/test_environment.py index 279bc4a13..627c2ddf9 100644 --- a/android/pylib/utils/test_environment.py +++ b/android/pylib/utils/test_environment.py @@ -5,19 +5,30 @@ import logging import os import psutil +import signal from pylib import android_commands + def _KillWebServers(): - for retry in xrange(5): - for server in ['lighttpd', 'web-page-replay']: - pids = [p.pid for p in psutil.process_iter() if server in p.name] - for pid in pids: + for s in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT, signal.SIGKILL]: + signalled = [] + for server in ['lighttpd', 'webpagereplay']: + for p in psutil.process_iter(): try: - logging.warning('Killing %s %s', server, pid) - os.kill(pid, signal.SIGQUIT) + if not server in ' '.join(p.cmdline): + continue + logging.info('Killing %s %s %s', s, server, p.pid) + p.send_signal(s) + signalled.append(p) except Exception as e: - logging.warning('Failed killing %s %s %s', server, pid, e) + logging.warning('Failed killing %s %s %s', server, p.pid, e) + for p in signalled: + try: + p.wait(1) + except Exception as e: + logging.warning('Failed waiting for %s to die. %s', p.pid, e) + def CleanupLeftoverProcesses():