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

前端 未结 8 1921
悲哀的现实
悲哀的现实 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:35

    Why Python (CPython and others) uses the GIL

    From http://wiki.python.org/moin/GlobalInterpreterLock

    In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiple native threads from executing Python bytecodes at once. This lock is necessary mainly because CPython's memory management is not thread-safe.

    How to remove it from Python?

    Like Lua, maybe Python could start multiple VM, But python doesn't do that, I guess there should be some other reasons.

    In Numpy or some other python extended library, sometimes, releasing the GIL to other threads could boost the efficiency of the whole programme.

提交回复
热议问题