def check_cpu(self):
while True:
try:
if self.pid is None:
time.sleep(0.2)
continue
proc = psutil.Process(self.pid)
cpu = 0
l = []
for x in xrange(20):
tmp = int(proc.cpu_percent(interval=0.1))
cpu += tmp
l.append(tmp)
if cpu is not None and (cpu <= 100 or l.count(0) > 10):
log("CPU at 0%, killing")
self.cpu_killed = True
self.do_kill()
break
else:
time.sleep(0.5)
except psutil.NoSuchProcess:
break
评论列表
文章目录