Python interpreter with the GIL lock

A, Python interpreter

write python .py files must be converted to want to run the code (0101 ...) CPU can be identified by the python interpreter. There are several python interpreter, developed by different languages, common explanation is as follows:

Cpython

Cpython is the official website of the recommended interpreter, it is written in C language development, after we downloaded from the official website python, python command line to run is started Cpython.

Ipython

Ipython is the addition of interactive features in Cpython basis, jupyter notebook is the use of ipython.

PyPy

PyPy is another python interpreter, his goal is speed of execution, he and Cpython different.

Jpython

Jpython interpreter is running on the Java platform, can be directly python code is compiled into Java bytecode execution.

IroPython

IronPython and Jython similar, but IronPython Python interpreter is running on the Microsoft .Net platform, Python code can be directly translated into .Net byte code.

 Two, GIL lock (global interpreter lock)

GIL: Each thread must first obtain GIL in the implementation process, to ensure that only one thread can execute code.

This is a drawback python interpreter in C language, which is a historical legacy, difficult to change.

Use Cpython interpreter, python can not play to the efficiency of multi-core CPU.

Compute-intensive program

For example, the calculation 1-1000000 cubic and, this time with the process.

IO intensive programs

File read and write, and other network transceivers. There is waiting, delay, you can use threads and coroutines.

 Third, how to solve the problem GIL

1. interpreter for a python

2. The use of other languages ​​to write the contents of python thread (such as C), and then use python call. Of course, you can also use other languages, it reflects the characteristics of the python glue language.

 

Reference links:

[1] https://www.liaoxuefeng.com/wiki/1016959663602400/1016966024263840

Guess you like

Origin www.cnblogs.com/yunxiaofei/p/11108869.html