threading
Stdlib — ConcurrencyPython 2.0+Advanced
Thread-based parallelism: Thread, Lock, RLock, Semaphore, Event, Condition
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
- Dependencies
- None — Python Standard Library
- Install
Included with Python
Learn by Difficulty
Quick Example
python
import threading results = [] def worker(n): results.append(n * n) threads = [threading.Thread(target=worker, args=(i,)) for i in range(5)] for t in threads: t.start() for t in threads: t.join() print(f"Results: {sorted(results)}")
The threading module is part of Python's standard library. Thread-based parallelism: Thread, Lock, RLock, Semaphore, Event, Condition.
Try in PlaygroundTags
stdlibconcurrencyparallelismthreadGIL
Related Items
multiprocessing
Stdlib — Concurrency
Process-based parallelism: Process, Pool, Queue, shared memory
concurrent.futures
Stdlib — Concurrency
High-level async execution: ThreadPoolExecutor, ProcessPoolExecutor
asyncio
Stdlib — Concurrency
Async I/O: event loop, coroutines, tasks, streams, queues
queue
Stdlib — Data
Thread-safe FIFO, LIFO, and priority queues