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

Side by Side Diff: scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py

Issue 2386073002: Wait cloudtail termination in goma module (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import errno 7 import errno
8 import os 8 import os
9 import signal 9 import signal
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 import time
12 13
13 from slave import goma_utils 14 from slave import goma_utils
14 15
15 16
16 def start_cloudtail(args): 17 def start_cloudtail(args):
17 """Write process id of started cloudtail to file object f""" 18 """Write process id of started cloudtail to file object f"""
18 19
19 proc = subprocess.Popen([args.cloudtail_path, 20 proc = subprocess.Popen([args.cloudtail_path,
20 'tail', 21 'tail',
21 '--log-id', 'goma_compiler_proxy', 22 '--log-id', 'goma_compiler_proxy',
22 '--path', 23 '--path',
23 goma_utils.GetLatestGomaCompilerProxyInfo()]) 24 goma_utils.GetLatestGomaCompilerProxyInfo()])
24 with open(args.pid_file, 'w') as f: 25 with open(args.pid_file, 'w') as f:
25 f.write(str(proc.pid)) 26 f.write(str(proc.pid))
26 27
28 def is_running_posix(pid):
29 try:
30 os.kill(pid, 0)
31 except OSError as e:
32 if e.errno == errno.ESRCH:
ukai 2016/10/03 02:52:52 kill may get errno.EPERM and I think we should ret
Vadim Sh. 2016/10/03 19:07:06 +1 for EPERM handling and returning false
tikuta 2016/10/04 03:45:26 Done.
33 return False
34 raise e
Yoshisato Yanagisawa 2016/10/03 04:49:05 So, in this case, we do not guarantee cloud tail d
tikuta 2016/10/04 03:45:25 I send SIGKILL
35 return True
36
27 def main(): 37 def main():
28 parser = argparse.ArgumentParser( 38 parser = argparse.ArgumentParser(
29 description='cloudtail utility for goma recipe module.') 39 description='cloudtail utility for goma recipe module.')
30 40
31 subparsers = parser.add_subparsers(help='commands for cloudtail') 41 subparsers = parser.add_subparsers(help='commands for cloudtail')
32 42
33 parser_start = subparsers.add_parser('start', 43 parser_start = subparsers.add_parser('start',
34 help='subcommand to start cloudtail') 44 help='subcommand to start cloudtail')
35 parser_start.set_defaults(command='start') 45 parser_start.set_defaults(command='start')
36 parser_start.add_argument('--cloudtail-path', required=True, 46 parser_start.add_argument('--cloudtail-path', required=True,
37 help='path of cloudtail binary') 47 help='path of cloudtail binary')
38 parser_start.add_argument('--pid-file', required=True, 48 parser_start.add_argument('--pid-file', required=True,
39 help='file written pid') 49 help='file written pid')
40 50
41 parser_stop = subparsers.add_parser('stop', 51 parser_stop = subparsers.add_parser('stop',
42 help='subcommand to stop cloudtail') 52 help='subcommand to stop cloudtail')
43 parser_stop.set_defaults(command='stop') 53 parser_stop.set_defaults(command='stop')
44 parser_stop.add_argument('--killed-pid-file', required=True, 54 parser_stop.add_argument('--killed-pid-file', required=True,
45 help='file written the pid to be killed.') 55 help='file written the pid to be killed.')
46 56
47 args = parser.parse_args() 57 args = parser.parse_args()
48 58
49 if args.command == 'start': 59 if args.command == 'start':
50 start_cloudtail(args) 60 start_cloudtail(args)
51 elif args.command == 'stop': 61 elif args.command == 'stop':
52 with open(args.killed_pid_file) as f: 62 with open(args.killed_pid_file) as f:
53 # cloudtail flushes log and terminates 63 # cloudtail flushes log and terminates
54 # within 5 seconds when it recieves SIGINT. 64 # within 5 seconds when it recieves SIGINT.
55 os.kill(int(f.read()), signal.SIGINT) 65 pid = int(f.read())
66 os.kill(pid, signal.SIGINT)
67 if os.name == 'nt':
ukai 2016/10/03 02:52:52 factor out a func to wait for pid?
Vadim Sh. 2016/10/03 19:07:06 +1
tikuta 2016/10/04 03:45:26 Done.
68 os.waitpid(pid, 0)
69 else:
70 while True:
ukai 2016/10/03 02:52:52 might be better to abandon if it tried >5 sec or s
Vadim Sh. 2016/10/03 19:07:06 +1 also nit while is_running_posix(pid): time.
tikuta 2016/10/04 03:45:26 Done.
71 if is_running_posix(pid):
72 time.sleep(1)
73 else:
74 break
56 75
57 if '__main__' == __name__: 76 if '__main__' == __name__:
58 sys.exit(main()) 77 sys.exit(main())
OLDNEW
« 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