Lesson 44 of 55
PythonMultiprocessing
20 minutes
Course progress80%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 44 of 55
Python20 minutes
Keep these ideas in mind as you work through the lesson.
The multiprocessing module sidesteps the GIL by spawning separate Python processes, each with its own interpreter and memory space—perfect for CPU‑bound work.
import multiprocessing
def square(x):
return x * x
if __name__ == '__main__':
with multiprocessing.Pool() as pool:
results = pool.map(square, range(10))
print('Squares:', results)
Data is passed between processes via serialization (pickle), so avoid sending huge objects when possible.