Python Glossary Русский

all Python 3Linux · macOSosfunction

os.nice

os — signals and priority

Increase a process's niceness, lowering its scheduling priority. Availability: Unix.

Syntax

os.nice(...)

The argument is an increment to the current value, not a new value; the resulting nice is returned. Higher nice means lower priority. Without superuser rights priority can only be lowered and cannot be restored. nice(0) simply reports the current value.

Examples

import os
print(os.nice(0))   # → ? только Unix: текущее значение nice, у обычного процесса 0
print(os.nice(5))   # → 5 — приоритет понижен на 5 пунктов, возвращается новое значение
print(os.nice(3))   # → 8 — инкременты складываются, значение не задаётся напрямую
print(os.nice(19))   # → 19 — nice упирается в максимум, 8 + 19 не даёт 27
os.nice(-1)   # → ? только Unix: PermissionError без прав root — вернуть приоритет обратно нельзя

See also

Open in the full glossarydocs.python.orgReport an inaccuracy