diff options
Diffstat (limited to 'catapult/devil/devil/android/forwarder.py')
-rw-r--r-- | catapult/devil/devil/android/forwarder.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/catapult/devil/devil/android/forwarder.py b/catapult/devil/devil/android/forwarder.py index 76c56ecc..cf1fbe14 100644 --- a/catapult/devil/devil/android/forwarder.py +++ b/catapult/devil/devil/android/forwarder.py @@ -5,6 +5,7 @@ # pylint: disable=W0212 import fcntl +import inspect import logging import os import psutil @@ -26,7 +27,11 @@ DYNAMIC_DEVICE_PORT = 0 def _GetProcessStartTime(pid): - return psutil.Process(pid).create_time + p = psutil.Process(pid) + if inspect.ismethod(p.create_time): + return p.create_time() + else: # Process.create_time is a property in old versions of psutil. + return p.create_time def _LogMapFailureDiagnostics(device): @@ -160,7 +165,7 @@ class Forwarder(object): device_errors.DeviceUnreachableError): # We don't want the failure to kill the device forwarder to # supersede the original failure to map. - logging.warning( + logger.warning( 'Failed to kill the device forwarder after map failure: %s', str(e)) _LogMapFailureDiagnostics(device) @@ -345,6 +350,9 @@ class Forwarder(object): """ # See if the host_forwarder daemon was already initialized by a concurrent # process or thread (in case multi-process sharding is not used). + # TODO(crbug.com/762005): Consider using a different implemention; relying + # on matching the string represantion of the process start time seems + # fragile. pid_for_lock = Forwarder._GetPidForLock() fd = os.open(Forwarder._LOCK_PATH, os.O_RDWR | os.O_CREAT) with os.fdopen(fd, 'r+') as pid_file: @@ -414,9 +422,10 @@ class Forwarder(object): logger.info('Killing host_forwarder.') try: kill_cmd = [self._host_forwarder_path, '--kill-server'] - (exit_code, _o) = cmd_helper.GetCmdStatusAndOutputWithTimeout( + (exit_code, output) = cmd_helper.GetCmdStatusAndOutputWithTimeout( kill_cmd, Forwarder._TIMEOUT) if exit_code != 0: + logger.warning('Forwarder unable to shut down:\n%s', output) kill_cmd = ['pkill', '-9', 'host_forwarder'] (exit_code, output) = cmd_helper.GetCmdStatusAndOutputWithTimeout( kill_cmd, Forwarder._TIMEOUT) |