Python 3.3+Linux · macOSosfunction
os.sched_yield
os — scheduler (sched)
Voluntarily yield the CPU to other runnable processes.
Syntax
os.sched_yield(...)
It yields the CPU but does not guarantee that another thread or process actually runs: with nobody waiting the call returns at once. It is no way to wait for a condition — a loop around sched_yield burns CPU. Python threads wait with threading.Event, Condition or queues.
Examples
import os
print(os.sched_yield()) # → None — функция ничего не возвращает
for _ in range(3): os.sched_yield() # → ? только Unix: трижды уступили процессор другим готовым процессам
os.sched_yield() # → ? только Unix: если готовых к выполнению процессов нет, управление возвращается немедленно
print(os.sched_getaffinity(0)) # → ? только Unix: ядра, между которыми планировщик и распределяет процесс, например {0, 1, 2, 3}
os.sched_yield(0) # → TypeError — sched_yield вызывается без аргументов
See also
Open in the full glossarydocs.python.orgReport an inaccuracy