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

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

    Python's GIL is intended to serialize access to interpreter internals from different threads. On multi-core systems, it means that multiple threads can't effectively make use of multiple cores. (If the GIL didn't lead to this problem, most people wouldn't care about the GIL - it's only being raised as an issue because of the increasing prevalence of multi-core systems.) If you want to understand it in detail, you can view this video or look at this set of slides. It might be too much information, but then you did ask for details :-)

    Note that Python's GIL is only really an issue for CPython, the reference implementation. Jython and IronPython don't have a GIL. As a Python developer, you don't generally come across the GIL unless you're writing a C extension. C extension writers need to release the GIL when their extensions do blocking I/O, so that other threads in the Python process get a chance to run.

提交回复
热议问题