🐍 Python Intermediate

What is Python's multiprocessing module?

Why Interviewers Ask This

Mid-level Python roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.

Answer

The multiprocessing module bypasses the GIL by creating separate OS processes with their own Python interpreter and memory space. For CPU-bound parallelism: from multiprocessing import Pool; with Pool(processes=4) as pool: results = pool.map(cpu_task, data_list). Process communication via Queue, Pipe, and shared memory (Value, Array). Synchronization with Lock, Semaphore, Event. Modern approach: concurrent.futures.ProcessPoolExecutor — higher-level and consistent API with ThreadPoolExecutor. Processes have higher startup overhead than threads and serialization cost for passing data between processes (via pickle). Use multiprocessing for CPU-intensive work: image processing, data analysis, scientific computation. For I/O-bound work, prefer asyncio or threads.

Common Mistake

Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex Python answers easy to follow.