๐ง Systems Concepts (read-only)
multiprocessing โ true parallelism
Bypass the GIL by spawning OS processes.
For CPU-bound work, spawn processes. Each has its own interpreter and GIL, so they run in parallel on multiple cores.
from multiprocessing import Pool
def square(n): return n * n
if __name__ == "__main__":
with Pool(4) as p:
print(p.map(square, range(8)))
# [0, 1, 4, 9, 16, 25, 36, 49]
**When to reach for it**
- Heavy math / image processing โ
PoolorProcessPoolExecutor. - Data must cross process boundaries โ use
Queue,Pipe, or shared memory. - Always guard the entry point with
if __name__ == "__main__":on Windows / macOS spawn-start.
> ๐งช Concept-only here โ the browser sandbox runs one process. Try the snippet in real CPython.