Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad?

|

👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!

I"m hoping someone can provide some insight as to what"s fundamentally different about the Java Virtual Machine that allows it to implement threads nicely without the need for a Global Interpreter Lock (GIL), while Python necessitates such an evil.

👻 Read also: what is the best laptop for engineering students?

Why is there no GIL in the Java Virtual Machine? Why does Python need one so bad? global interpreter lock: Questions

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

1 answers

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 so important. I have never written a compiler nor an interpreter myself, so don"t be frugal with details, I"ll probably need them to understand.

258

Answer #1

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.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method