Use this when Python CPU-heavy work needs multiple cores.
Multiprocessing · Python Automation
Python multiprocessing runs functions in separate processes with Pool or concurrent.futures.ProcessPoolExecutor, using several CPU cores for CPU-heavy automation tasks.
1. Threads for I/O-bound, processes for CPU-bound work.
2. concurrent.futures for simple pools.
3. Limit workers to protect targets.
4. Collect exceptions from futures.
5. Avoid shared mutable state.
tasks → worker pool → results
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
- Unbounded parallelism overloading devices or AAA servers.
- Shared mutable state between workers.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Process pools run work on several CPU cores.
- They use more memory than threads.
- Arguments and results are pickled.
python3 -c 'import multiprocessing;print(multiprocessing.cpu_count())'— CPUs- concurrent.futures ThreadPoolExecutor/ProcessPoolExecutor — pools
- max_workers limit — target protection
ReferenceWhy it matters1 section · depth on demand
What it is
multiprocessing runs work in separate processes, using several CPU cores; concurrent.futures gives a simpler pool API. For network I/O, threads or asyncio are usually enough.
ReferenceImportant terms & boundaries2 sections · depth on demand
How it works
Example
from concurrent.futures import ProcessPoolExecutor
def parse_config(path): # CPU-heavy work: parsing, diffing, rendering
...
if __name__ == "__main__":
with ProcessPoolExecutor(max_workers=4) as pool:
results = list(pool.map(parse_config, config_files))
Use processes for CPU-bound work, because each process has its own interpreter and avoids the GIL. For I/O-bound work such as SSH or API calls to many devices, ThreadPoolExecutor or asyncio is usually lighter and enough.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Python Automation > Multiprocessing. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.python.org/3/ · confidence 94%