Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Unified Diff: scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py

Issue 2386073002: Wait cloudtail termination in goma module (Closed)
Patch Set: finally -> except Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 79f20dc1edd7c1ee81c9d20086e9b363e61c5bb5..09152f2e365d3d4952f0b6ffbdaeb31b73546929 100644
--- a/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py
+++ b/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py
@@ -9,6 +9,7 @@ import os
import signal
import subprocess
import sys
+import time
from slave import goma_utils
@@ -24,6 +25,38 @@ def start_cloudtail(args):
with open(args.pid_file, 'w') as f:
f.write(str(proc.pid))
+def is_running_posix(pid):
+ """Return True if process of pid is running."""
ukai 2016/10/05 01:08:32 Args: Returns: Raises:
tikuta 2016/10/05 04:16:28 Done.
+
+ try:
+ os.kill(pid, 0)
+ except OSError as e:
+ if e.errno == errno.ESRCH or e.errno == errno.EPERM:
+ return False
+ os.kill(pid, signal.SIGKILL)
+ raise e
+ return True
+
+def wait_termination(pid):
+ """Wait termination of pid."""
ukai 2016/10/05 01:08:32 Send SIGINT and wait .. ? Args: Raises:
tikuta 2016/10/05 04:16:28 Done.
+
+ try:
+ os.kill(pid, signal.SIGINT)
+ except:
+ os.kill(pid, signal.SIGKILL)
+ raise
+
+ if os.name == 'nt':
+ os.waitpid(pid, 0)
+ else:
+ for _ in range(10):
Yoshisato Yanagisawa 2016/10/05 02:15:42 nit xrange?
tikuta 2016/10/05 04:16:28 Done.
+ if not is_running_posix(pid):
+ break
+ time.sleep(1)
+
+ if is_running_posix(pid):
+ os.kill(pid, signal.SIGKILL)
Yoshisato Yanagisawa 2016/10/05 02:15:42 not sure but no need to print you killed the proce
tikuta 2016/10/05 04:16:28 Done. It is needed.
+
def main():
parser = argparse.ArgumentParser(
description='cloudtail utility for goma recipe module.')
@@ -52,7 +85,7 @@ def main():
with open(args.killed_pid_file) as f:
# cloudtail flushes log and terminates
# within 5 seconds when it recieves SIGINT.
- os.kill(int(f.read()), signal.SIGINT)
+ wait_termination(int(f.read()))
if '__main__' == __name__:
sys.exit(main())
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698