Concurrency and Process Modules

threading

Thread-based concurrency, synchronization and thread-local state. Threads share process memory, so protect compound shared-state operations with synchronization. The usual GIL-enabled CPython build limits parallel execution of Python bytecode; free-threaded builds differ.

Formal Syntax & Structure

python syntaxpython
import threading

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from threading import Thread, Eventready = Event()worker = Thread(target=ready.set)worker.start()worker.join()print(ready.is_set())
Python Reference