Use this when CPU-heavy Python tasks need several cores.
Multiprocessing · Parallelism & Concurrency
Multiprocessing runs work in separate processes on several CPU cores, such as Python multiprocessing, which avoids the GIL for CPU-heavy tasks at the cost of more memory and inter-process communication.
1. Processes for CPU-bound tasks.
2. Higher overhead.
3. Arguments must be picklable.
4. Watch memory.
5. Bound pool size.
tasks → process 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
- Large data copied between processes.
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.
- Separate processes avoid Python's GIL.
- Each process uses more memory.
- Data passed between processes is pickled.
- ProcessPoolExecutor for CPU-bound work — parallelism
- Picklable arguments — compatibility
- Memory per process — resources
ReferenceWhy it matters1 section · depth on demand
What it is
Multiprocessing runs work in separate OS processes, each with its own Python interpreter, so CPU-bound work can use several cores (Python threads are limited by the GIL for CPU work). Data passed between processes must be pickled.
ReferenceImportant terms & boundaries2 sections · depth on demand
Example
from concurrent.futures import ProcessPoolExecutor
with ProcessPoolExecutor(max_workers=4) as pool:
results = list(pool.map(parse_config, files))
In depth
Multiprocessing runs work in several operating-system processes at once, each with its own memory. In Python it bypasses the global interpreter lock, so it suits CPU-heavy tasks such as parsing large files or rendering many templates. For network automation, which mostly waits on I/O, threads or asyncio are usually simpler.
from concurrent.futures import ProcessPoolExecutor
with ProcessPoolExecutor(max_workers=4) as pool:
results = list(pool.map(parse_config, config_files))
Things to know: arguments and results are copied between processes (keep them small and picklable), each process opens its own connections, and memory use multiplies with the number of workers. Set max_workers near the number of CPU cores for CPU-bound work.
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 Parallelism & Concurrency > Multiprocessing. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.python.org/3/library/concurrent.futures.html · confidence 94%