Unfortunately, in many cases Python can only run one thread at a
time, due to what’s know as the Global Interpreter Lock (“GIL”).
Other times it can run multiple threads just fine—it all depends on
the specific usage patterns.
But which usage patterns allow parallelism, and which don’t?
Naive mental models will give you inaccurate answers. So in this
article you’ll build a practical mental model of how the GIL works:
- We’ll start by going through a series of increasingly more
accurate mental models of how the GIL works.
- Then, we’ll see how our new, more accurate mental model can help
you predict where and whether parallelism bottlenecks will occur.