threading.current_thread
Prev: threading.Condition | Up: threading | Next: threading.enumerate
Rel: threading.active_count, threading.Barrier, threading.BoundedSemaphore, threading.BrokenBarrierError
Ref: docs.python.org — threading.current_thread
Tags: #public #python3 #stdlib #threading
Import
import threading
from threading import current_thread
Signature & Overview
threading.current_thread()
Return the current Thread object, corresponding to the caller's thread of control.
Usage
import threading
cur = threading.current_thread()
assert isinstance(cur, threading.Thread) and cur.is_alive()
Gotchas
- Use
current_thread()(not deprecatedcurrentThread()): Helpful in logging or asserting you're running on a worker vs. main thread.
REPL Inspect
from threading import current_thread
help(current_thread)
Linked from
Related notes
- tuts/python3/stdlib_module/threading/Condition Linked here; links to this page; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/enumerate Linked here; links to this page; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/threading/active_count Linked here; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/Barrier Linked here; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/BoundedSemaphore Linked here; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/BrokenBarrierError Linked here; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/Event shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/excepthook shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/ExceptHookArgs shared tags: #stdlib, #threading