GIL全局解释器锁
拓展 什么是GIL全局解释器锁 为什么要有GIL全局解释器锁? GIL全局解释器锁的优缺点 多线程和IO密集型的应用场景 转载文章 TOC 拓展 python解释器: Cpython C语言写的 Jpython java语言写的 什么是GIL全局解释器锁 在同一个进程下开启的多线程,同一时刻只能有一个线程执行,因为Cpython的内存管理不是线程安全 摘自官方文档解释: 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. (However, since the GIL exists, other features have grown to depend on the guarantees that it enforces.) 结论:在Cpython解释器中,同一个进程下开启的多线程,同一时刻只能有一个线程执行,无法利用多核优势。 为什么要有GIL全局解释器锁?