Versuch mal das als root laufen zu lassen:
Python
#!/usr/bin/env python3
import psutil
import time
from collections import deque
collect_intervals = 5
interval = 60
threshold = 99.9 * collect_intervals
cpu_usage_history = deque(maxlen=collect_intervals)
while True:
try:
vdr_process = next(p for p in psutil.process_iter() if p.name() == 'vdr')
except StopIteration:
cpu_usage_history.clear()
time.sleep(1)
continue
cpu_usage_history.append(vdr_process.cpu_percent(interval))
print(f"cpu usage over the last {interval * len(cpu_usage_history)} seconds was: {list(cpu_usage_history)}")
if sum(cpu_usage_history) >= threshold:
print("kill vdr...")
cpu_usage_history.clear()
vdr_process.kill()
Alles anzeigen