Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.2 - GIL - good/bad?

Tags:

Python 3.2 ALPHA is out.

From the Change Log, it appears the GIL has been entirely rewritten.

A few questions:

  1. Is having a GIL good or bad? (and why).
  2. Is the new GIL better? If so, how?

UPDATE:

I'm fairly new to Python. So all of this is new to my but I do at least understand that the existence of a GIL with CPython is a huge deal.

Question though, why does CPython not just clone the interpreter like Perl does in an attempt to remove the need for the GIL?

like image 746
JerryK Avatar asked Aug 02 '10 01:08

JerryK


People also ask

Does Python 3 have GIL?

You can't argue with the single-threaded performance benefits of the GIL. So the result is that Python 3 still has the GIL.

Does Python still have GIL?

The GIL's low performance overhead really shines for single-threaded operations, including I/O-multiplexed programs where libraries like asyncio are used, and this is still a predominant use of Python.

How do you overcome GIL in Python?

This is achieved by preventing threads to use the Python interpreter simultaneously while they run. Use threaded extensions in C where GIL is not a problem (Numexpr, NumPy with MKL, SciPy with FFTW...): Pro: powerful and very easy to use.

What is GIL in Python and the pros and cons of it?

GIL or Global Interpreter Lock Generally, Python uses a single thread to run a single process. We get the same performance result of the single-threaded and multi-threaded processes using the GIL. It restricts achieving multithreading in Python because it prevents the threads and works as a single thread.


1 Answers

The best explanation I've seen as to why the GIL sucks is here:

http://www.dabeaz.com/python/GIL.pdf

And the same guy has a presentation on the new GIL here:

http://www.dabeaz.com/python/NewGIL.pdf

If that's all that's been done it still sucks - just not as bad. Multiple threads will behave better. Multi-core will still do nothing for you with a single python app.

like image 93
phkahler Avatar answered Sep 18 '22 17:09

phkahler