OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 import logging | 5 import logging |
6 import os | 6 import os |
7 import psutil | 7 import psutil |
8 import signal | |
8 | 9 |
9 from pylib import android_commands | 10 from pylib import android_commands |
10 | 11 |
11 def _KillWebServers(): | 12 def _KillWebServers(): |
12 for retry in xrange(5): | 13 for retry in xrange(5): |
13 for server in ['lighttpd', 'web-page-replay']: | 14 for server in ['lighttpd', 'web-page-replay', 'webpagereplay']: |
tonyg
2013/12/06 17:49:53
Do we really need both with and without the dashes
bulach
2013/12/06 18:12:56
right, I think at some point it had the dashes, bu
| |
14 pids = [p.pid for p in psutil.process_iter() if server in p.name] | 15 for p in psutil.process_iter(): |
15 for pid in pids: | |
16 try: | 16 try: |
17 logging.warning('Killing %s %s', server, pid) | 17 if not server in ' '.join(p.cmdline): |
18 os.kill(pid, signal.SIGQUIT) | 18 continue |
19 logging.warning('Killing %s %s', server, p.pid) | |
20 p.send_signal(signal.SIGQUIT) | |
21 p.wait(1) | |
tonyg
2013/12/06 17:49:53
I didn't think wait took args. What does this do?
tonyg
2013/12/06 17:49:53
Let's parallelize this by having two loops. The fi
bulach
2013/12/06 18:12:56
good idea!
the arg is a timeout for waiting the pr
| |
19 except Exception as e: | 22 except Exception as e: |
20 logging.warning('Failed killing %s %s %s', server, pid, e) | 23 logging.warning('Failed killing %s %s %s', server, p.pid, e) |
21 | 24 |
22 | 25 |
23 def CleanupLeftoverProcesses(): | 26 def CleanupLeftoverProcesses(): |
24 """Clean up the test environment, restarting fresh adb and HTTP daemons.""" | 27 """Clean up the test environment, restarting fresh adb and HTTP daemons.""" |
25 _KillWebServers() | 28 _KillWebServers() |
26 did_restart_host_adb = False | 29 did_restart_host_adb = False |
27 for device in android_commands.GetAttachedDevices(): | 30 for device in android_commands.GetAttachedDevices(): |
28 adb = android_commands.AndroidCommands(device, api_strict_mode=True) | 31 adb = android_commands.AndroidCommands(device, api_strict_mode=True) |
29 # Make sure we restart the host adb server only once. | 32 # Make sure we restart the host adb server only once. |
30 if not did_restart_host_adb: | 33 if not did_restart_host_adb: |
31 adb.RestartAdbServer() | 34 adb.RestartAdbServer() |
32 did_restart_host_adb = True | 35 did_restart_host_adb = True |
33 adb.RestartAdbdOnDevice() | 36 adb.RestartAdbdOnDevice() |
34 adb.EnableAdbRoot() | 37 adb.EnableAdbRoot() |
35 adb.WaitForDevicePm() | 38 adb.WaitForDevicePm() |
OLD | NEW |