Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 59 |
| 60 Args: | 60 Args: |
| 61 pid(int): pid of process which this function waits termination. | 61 pid(int): pid of process which this function waits termination. |
| 62 | 62 |
| 63 Raises: | 63 Raises: |
| 64 OSError: is_running_posix, os.waitpid and os.kill may throw OSError. | 64 OSError: is_running_posix, os.waitpid and os.kill may throw OSError. |
| 65 NotDiedError: if cloudtail is running after 10 seconds waiting, | 65 NotDiedError: if cloudtail is running after 10 seconds waiting, |
| 66 NotDiedError is raised. | 66 NotDiedError is raised. |
| 67 """ | 67 """ |
| 68 | 68 |
| 69 # TODO(yyanagisawa): need to handle the case cloudtail is not running? | |
| 69 os.kill(pid, signal.SIGINT) | 70 os.kill(pid, signal.SIGINT) |
| 70 | 71 |
| 72 print('SIGINT has been sent to process %d. ' | |
| 73 'Going to wait for the process finishes.' % pid) | |
| 71 if os.name == 'nt': | 74 if os.name == 'nt': |
| 72 try: | 75 try: |
| 73 os.waitpid(pid, 0) | 76 os.waitpid(pid, 0) |
| 74 except OSError as e: | 77 except OSError as e: |
| 75 if e.errno == errno.ECHILD: | 78 if e.errno == errno.ECHILD: |
| 76 print('process of pid %d died before waitpitd' % pid) | 79 print('process %d died before waitpitd' % pid) |
| 77 return | 80 return |
| 78 raise e | 81 raise e |
| 79 else: | 82 else: |
| 80 for _ in xrange(10): | 83 for _ in xrange(10): |
| 81 time.sleep(1) | 84 time.sleep(1) |
| 82 if not is_running_posix(pid): | 85 if not is_running_posix(pid): |
| 83 return | 86 return |
| 84 | 87 |
| 85 print('process %d running more than 10 seconds' % pid) | 88 print('process %d running more than 10 seconds' % pid) |
| 86 raise NotDiedError() | 89 raise NotDiedError() |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 108 | 111 |
| 109 args = parser.parse_args() | 112 args = parser.parse_args() |
| 110 | 113 |
| 111 if args.command == 'start': | 114 if args.command == 'start': |
| 112 start_cloudtail(args) | 115 start_cloudtail(args) |
| 113 elif args.command == 'stop': | 116 elif args.command == 'stop': |
| 114 with open(args.killed_pid_file) as f: | 117 with open(args.killed_pid_file) as f: |
| 115 # cloudtail flushes log and terminates | 118 # cloudtail flushes log and terminates |
| 116 # within 5 seconds when it recieves SIGINT. | 119 # within 5 seconds when it recieves SIGINT. |
| 117 pid = int(f.read()) | 120 pid = int(f.read()) |
| 118 try: | 121 try: |
| 119 wait_termination(pid) | 122 wait_termination(pid) |
| 120 except (OSError, NotDiedError) as e: | 123 except (OSError, NotDiedError) as e: |
| 121 os.kill(pid, signal.SIGKILL) | 124 print('Going to send SIGTERM to process %d due to Error %s' % (pid, e)) |
| 122 print('killed process %d due to Error %s' % (pid, e)) | 125 # Since Windows does not have SIGKILL, we need to use SIGTERM. |
| 123 raise e | 126 os.kill(pid, signal.SIGTERM) |
|
ukai
2016/10/19 04:16:27
cloudtail doesn't handle SIGTERM to process someth
Yoshisato Yanagisawa
2016/10/19 04:27:24
It seems not?
https://chromium.googlesource.com/i
| |
| 127 # We do not reraise because I believe not suspending the process | |
| 128 # is more important than completely killing cloudtail. | |
| 124 | 129 |
| 125 | 130 |
| 126 if '__main__' == __name__: | 131 if '__main__' == __name__: |
| 127 sys.exit(main()) | 132 sys.exit(main()) |
| OLD | NEW |