threading.current_thread()
threading.current_thread() is a Python function in the Threading Module category. Returns the current Thread object corresponding to the caller's thread of control. The syntax is threading.current_thread(). Returns: Thread object. A typical example: t = threading.current_thread()
print(t.name) # "MainThread". A close sibling is threading.Thread(), which creates a new thread object that runs the target function with args. A close sibling is thread.Thread.start(), which starts the thread activity. Must be called at most once per thread. A close sibling is thread.Thread.join(), which waits for the thread to terminate. Blocks until timeout or completion. A close sibling is threading.Lock(), which creates a new primitive lock (mutex). Only one thread can acquire the lock at a time. More about this category: Thread-based parallelism — Thread, Lock, Semaphore, Event, Timer. Related Threading Module entries: threading.Thread(), thread.Thread.start(), thread.Thread.join(), threading.Lock(), threading.RLock(), threading.Semaphore(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.