-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathadbwatch.py
58 lines (46 loc) · 1.24 KB
/
adbwatch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import subprocess
import time
from threading import Timer
def run(cmd, timeout_sec):
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
timer = Timer(timeout_sec, proc.kill)
try:
timer.start()
stdout,stderr = proc.communicate()
finally:
timer.cancel()
return stdout
def IsAdbHung():
out = run(['adb', 'devices'], 60)
return len(out) == 0
def KillAdb():
import psutil
print("adb is hung, restarting...")
for proc in psutil.process_iter():
if proc.name() == "adb.exe":
proc.kill()
def SetAdbAffinity():
import psutil
for proc in psutil.process_iter():
if proc.name() == "adb.exe":
proc.cpu_affinity([0])
def main():
try:
import psutil
except:
print("psutil is required")
exit()
print("Monitoring adb for hangs...")
try:
IsAdbHung()
SetAdbAffinity()
while True:
if IsAdbHung():
KillAdb()
IsAdbHung()
SetAdbAffinity()
time.sleep(60)
except KeyboardInterrupt:
print("Exiting...")
if '__main__' == __name__:
main()