def wait_for_idle(self, timeout=30):
"""Wait for the system to go idle for at least 2 seconds"""
import monotonic
import psutil
logging.debug("Waiting for Idle...")
cpu_count = psutil.cpu_count()
if cpu_count > 0:
target_pct = 50. / float(cpu_count)
idle_start = None
end_time = monotonic.monotonic() + timeout
idle = False
while not idle and monotonic.monotonic() < end_time:
self.alive()
check_start = monotonic.monotonic()
pct = psutil.cpu_percent(interval=0.5)
if pct <= target_pct:
if idle_start is None:
idle_start = check_start
if monotonic.monotonic() - idle_start > 2:
idle = True
else:
idle_start = None
评论列表
文章目录