What is the global interpreter lock (GIL) in CPython?

前端 未结 8 1938
悲哀的现实
悲哀的现实 2020-11-21 08:53

What is a global interpreter lock and why is it an issue?

A lot of noise has been made around removing the GIL from Python, and I\'d like to understand why that is s

8条回答
  •  一个人的身影
    2020-11-21 09:39

    Suppose you have multiple threads which don't really touch each other's data. Those should execute as independently as possible. If you have a "global lock" which you need to acquire in order to (say) call a function, that can end up as a bottleneck. You can wind up not getting much benefit from having multiple threads in the first place.

    To put it into a real world analogy: imagine 100 developers working at a company with only a single coffee mug. Most of the developers would spend their time waiting for coffee instead of coding.

    None of this is Python-specific - I don't know the details of what Python needed a GIL for in the first place. However, hopefully it's given you a better idea of the general concept.

提交回复
热议问题