When Python can’t thread: a deep-dive into the GIL’s impact

Most computers these days come with multiple cores, allowing multiple threads to run computations in parallel.
And even without multiple cores, you can have concurrency, for example one thread waiting on disk while another runs code on the CPU.
The ability to use parallelism can be critical to scaling your application—or making your data processing finish faster.

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:

 

 

 

To finish reading, please visit source site