Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can an interpretive language avoid using Global Interpreter lock (GIL)?

CPython uses a Global Interpreter Lock. Linux has removed all traces of the Big Kernel Lock. What is the alternative to these locks? How can a system make full use of a truly multi-core or multi-processor system without grinding everything to a halt?

like image 224
rook Avatar asked Mar 03 '11 07:03

rook


2 Answers

A GIL wouldn't be necessary if python used a more advanced Garbage Collector like IBM's Recycler instated of a primitive reference counting method. This is something that Unladen Swallow is doing to improve the performance of python. A more prommising answer is Stackless Python, which uses its own micro-thread implementation instead of relying on the operating system like traditional CPython.

like image 188
rook Avatar answered Nov 11 '22 14:11

rook


The GIL is process specific, so you can get around it by launching several Python processes. The multiprocessing module provides an easy-to-use API for this.

Another way is to use C-extensions (or write your own) which release the GIL while doing the kind of data processing you need.

like image 2
shang Avatar answered Nov 11 '22 16:11

shang