Concurrent Execution

threading — Thread-based parallelism

Source code: Lib/threading.py

_thread — Low-level threading API

This module provides low-level primitives for working with multiple threads (also called light-weight processes or tasks) — multiple threads of control sharing their global data space. For synchronization, simple locks (also called mutexes or binary semaphores) are provided. The threading module provides an easier to use and higher-level threading API built on top of this module.

contextvars — Context Variables

This module provides APIs to manage, store, and access context-local state. The ContextVar class is used to declare and work with Context Variables. The copy_context() function and the Context class should be used to manage the current context in asynchronous frameworks.

sched — Event scheduler

Source code: Lib/sched.py

subprocess — Subprocess management

Source code: Lib/subprocess.py

concurrent.futures — Launching parallel tasks

Source code: Lib/concurrent/futures/thread.py and Lib/concurrent/futures/process.py

The concurrent package

Currently, there is only one module in this package:

multiprocessing.shared_memory — Provides shared memory for direct access across processes

Source code: Lib/multiprocessing/shared_memory.py

multiprocessing — Process-based parallelism

Source code: Lib/multiprocessing/

queue — A synchronized queue class

Source code: Lib/queue.py