Python 3.7+Linux · macOStimefunction
time.pthread_getcpuclockid()
POSIX clocks
Returns the clk_id of the CPU-time clock of the given thread, for use with clock_gettime(). Unix only: Linux and macOS.
Syntax
time.pthread_getcpuclockid(thread_id)
Unlike thread_time(), which measures only the current thread, this lets you read another thread's CPU time. Get the id from threading.get_ident() or Thread.ident; passing the id of a finished thread is undefined behaviour up to crashing the interpreter, so only ask about live threads.
Examples
import threading, time
clk = time.pthread_getcpuclockid(threading.get_ident()) # → ? на Windows AttributeError
print(time.clock_gettime(clk) >= 0) # → True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy