Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cpu_percent(interval=0.01):
- """Return the current system-wide CPU utilization as a percentage.
- Interval
- """
- t1 = cpu_times()
- t1_all = sum(t1)
- t1_busy = t1_all - t1.idle
- time.sleep(interval)
- t2 = cpu_times()
- t2_all = sum(t2)
- t2_busy = t2_all - t2.idle
- busy_delta = t2_busy - t1_busy
- difference = t2_all - t1_all
- try:
- busy_perc = (busy_delta / difference) * 100
- if busy_perc < 0.0:
- raise ZeroDivisionError
- except ZeroDivisionError:
- raise ValueError("inverval too low")
- else:
- return float(busy_perc)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement