How do `multiprocessing` and `ProcessPoolExecutor` differ from threads in practice?
AdvancedConceptConcurrency: threads, processes & asyncio
Answer
Each worker is a separate OS process with its own memory and GIL, so CPU-bound work scales across cores. Costs: start-up time, memory per process, and every argument and result is pickled and sent over a pipe (lambdas, open sockets and boto3 clients cannot be pickled). Start methods: fork (Linux default before 3.14, fast but unsafe with threads), spawn (macOS/Windows default, re-imports your module, which is why the __main__ guard is required), forkserver (Linux default from 3.14).
More on Concurrency: threads, processes & asyncio
What is the GIL, and what does it mean for DevOps scripts?IntermediateHow do you use `ThreadPoolExecutor` for parallel API calls?BeginnerThreads vs processes vs asyncio: how do you choose?IntermediateWhat is a race condition, and how do you prevent one in threaded code?IntermediateHow does a producer/consumer pattern with `queue.Queue` work?AdvancedWhat are coroutines, `async def` and `await`?Intermediate