Python 3.3+Linux · macOSosfunction
os.setpriority
os — signals and priority
Set the scheduling priority (nice) of a process/group/user. Availability: Unix.
Syntax
os.setpriority(...)
It sets an absolute value rather than an increment as nice does. Raising priority (lowering the value) without superuser rights raises PermissionError. Background processing that must not disturb interactive work usually gets 10 or 19.
Examples
import os
os.setpriority(os.PRIO_PROCESS, 0, 10) # → ? только Unix: None; текущему процессу (who=0) назначен nice 10 — значение задаётся, а не прибавляется, как в os.nice
print(os.getpriority(os.PRIO_PROCESS, 0)) # → ? только Unix: 10
os.setpriority(os.PRIO_PGRP, 0, 15) # → ? только Unix: nice 15 сразу всей группе процессов
import os
import subprocess; proc = subprocess.Popen(['sleep', '60']) # → ? фоновый потомок запущен
os.setpriority(os.PRIO_PROCESS, proc.pid, 19) # → ? только Unix: тяжёлая фоновая задача понижена до минимального приоритета
os.setpriority(os.PRIO_PROCESS, 0, -5) # → ? только Unix: PermissionError без прав root — повышать приоритет нельзя
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy