all Python 3Linux · macOSosfunction
os.wait3
os — waiting for processes
Like wait, but also returns resource-usage info (rusage). Availability: Unix.
Syntax
os.wait3(...)
Like wait it waits for any child, and in addition returns a resource.struct_rusage object with resource usage: CPU time, peak memory (ru_maxrss), context switches. ru_maxrss units differ: kilobytes on Linux, bytes on macOS.
Examples
import os
if os.fork() == 0: os._exit(0) # → ? только Unix: ребёнок завершается сразу, родителю будет кого дождаться
child, status, rusage = os.wait3(0) # options обязателен: 0 — блокирующее ожидание любого ребёнка
print(child, os.waitstatus_to_exitcode(status)) # → ? только Unix: pid ребёнка и 0, например «12347 0»
print(rusage.ru_maxrss) # → ? только Unix: пиковая память ребёнка (на Linux — в килобайтах), например 3200 — этого os.wait не возвращает
print(os.wait3(os.WNOHANG)) # → ChildProcessError — WNOHANG не блокирует, но и детей уже не осталось
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy