| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # pylint: disable=W0212 | 5 # pylint: disable=W0212 |
| 6 | 6 |
| 7 import fcntl | 7 import fcntl |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import psutil | 10 import psutil |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 @staticmethod | 242 @staticmethod |
| 243 def _GetPidForLock(): | 243 def _GetPidForLock(): |
| 244 """Returns the PID used for host_forwarder initialization. | 244 """Returns the PID used for host_forwarder initialization. |
| 245 | 245 |
| 246 In case multi-process sharding is used, the PID of the "sharder" is used. | 246 In case multi-process sharding is used, the PID of the "sharder" is used. |
| 247 The "sharder" is the initial process that forks that is the parent process. | 247 The "sharder" is the initial process that forks that is the parent process. |
| 248 By default, multi-processing is not used. In that case the PID of the | 248 By default, multi-processing is not used. In that case the PID of the |
| 249 current process is returned. | 249 current process is returned. |
| 250 """ | 250 """ |
| 251 use_multiprocessing = Forwarder._MULTIPROCESSING_ENV_VAR in os.environ | 251 use_multiprocessing = Forwarder._MULTIPROCESSING_ENV_VAR in os.environ |
| 252 return os.getppid() if use_multiprocessing else os.getpid() | 252 return os.getpgrp() if use_multiprocessing else os.getpid() |
| 253 | 253 |
| 254 def _InitHostLocked(self): | 254 def _InitHostLocked(self): |
| 255 """Initializes the host forwarder daemon. | 255 """Initializes the host forwarder daemon. |
| 256 | 256 |
| 257 Note that the global lock must be acquired before calling this method. This | 257 Note that the global lock must be acquired before calling this method. This |
| 258 method kills any existing host_forwarder process that could be stale. | 258 method kills any existing host_forwarder process that could be stale. |
| 259 """ | 259 """ |
| 260 # See if the host_forwarder daemon was already initialized by a concurrent | 260 # See if the host_forwarder daemon was already initialized by a concurrent |
| 261 # process or thread (in case multi-process sharding is not used). | 261 # process or thread (in case multi-process sharding is not used). |
| 262 pid_for_lock = Forwarder._GetPidForLock() | 262 pid_for_lock = Forwarder._GetPidForLock() |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 # sure that the old version of device_forwarder (not supporting | 340 # sure that the old version of device_forwarder (not supporting |
| 341 # 'kill-server') is not running on the bots anymore. | 341 # 'kill-server') is not running on the bots anymore. |
| 342 timeout_sec = 5 | 342 timeout_sec = 5 |
| 343 try: | 343 try: |
| 344 device.KillAll( | 344 device.KillAll( |
| 345 'device_forwarder', blocking=True, timeout=timeout_sec) | 345 'device_forwarder', blocking=True, timeout=timeout_sec) |
| 346 except device_errors.CommandFailedError: | 346 except device_errors.CommandFailedError: |
| 347 pids = device.old_interface.ExtractPid('device_forwarder') | 347 pids = device.old_interface.ExtractPid('device_forwarder') |
| 348 if pids: | 348 if pids: |
| 349 raise | 349 raise |
| OLD | NEW |