Python Glossary Русский

all Python 3Linux · macOSosfunction

os.getloadavg

os — system

Return the system load average over 1, 5 and 15 minutes. Availability: Unix.

Syntax

os.getloadavg(...)

Load average is the average number of processes ready to run — on Linux also those waiting for disk; it is not a percentage. Judge it against the processor count: a load of 4 on four cores is full utilisation, on sixteen it is light. If the value cannot be obtained, OSError is raised.

Examples

import os
print(os.getloadavg())  # → ? только Unix: кортеж из трёх float, например (0.52, 0.48, 0.41); на Windows — AttributeError
load1, load5, load15 = os.getloadavg()  # → ? только Unix: средние за 1, 5 и 15 минут
print(round(load1 / (os.cpu_count() or 1), 2))  # → ? только Unix: нагрузка на одно ядро, например 0.07
print(load1 > load15)  # → True, если за последнюю минуту нагрузка выросла

See also

Open in the full glossarydocs.python.orgReport an inaccuracy