Lesson 44 of 55 · Python
Multiprocessing
Duration: 20 minutes
Lesson 44 of 55 · Python
Duration: 20 minutes
multiprocessing module sidesteps the GIL by spawning separate Python processes, each with its own interpreter and memory space—perfect for CPU‑bound work.\n\npython\nimport multiprocessing\n\ndef square(x):\n return x * x\n\nif __name__ == '__main__':\n with multiprocessing.Pool() as pool:\n results = pool.map(square, range(10))\n print('Squares:', results)\n\n\nData is passed between processes via serialization (pickle), so avoid sending huge objects when possible.\n