Python 3.7+timefunction
time.thread_time()
clocks and timing
CPU time of the current thread only, in seconds: how much processor time this particular thread used, excluding sleep.
Syntax
time.thread_time() -> float
A difference is meaningful only if both calls happen in the same thread: a value from another thread comes from a different counter. Unlike process_time(), work in sibling threads is not included, which shows which thread is loading the CPU. A thread waiting on a lock or I/O accumulates almost no time.
Examples
import threading, time
def work():
t0 = time.thread_time()
sum(range(300_000))
print(time.thread_time() - t0 >= 0) # → True
th = threading.Thread(target=work)
th.start()
th.join()
See also
Open in the full glossarydocs.python.orgReport an inaccuracy