views:

289

answers:

3

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?

+2  A: 

Is having a GIL good or bad? (and why).

Neither -- or both. It's necessary for thread synchronization.

Is the new GIL better? If so, how?

Have you run any benchmarks? If not, then perhaps you should (1) run a benchmark, (2) post the benchmark in the question and (3) ask specific questions about the benchmark results.

Discussing the GIL in vague, handwaving ways is largely a waste of time.

Discussing the GIL in the specific context of your benchmark, however, can lead to a solution to your performance problem.

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

Read this: http://perldoc.perl.org/perlthrtut.html

First, PERL didn't support threads at all. Older PERL interpreters had a buggy module that didn't work correctly.

Second, the newer PERL interpreter has this feature.

The biggest difference between Perl ithreads and the old 5.005 style threading, or for that matter, to most other threading systems out there, is that by default, no data is shared. When a new Perl thread is created, all the data associated with the current thread is copied to the new thread, and is subsequently private to that new thread!

Since the PERL (only specific data is shared) model is different from Python's (all data is shared) model, copying the PERL interpreter would fundamentally break Python's threads. The PERL thread model is fundamentally different.

S.Lott
I'm fairly new to Python but have read enough to at least understand the GIL is a big deal, which is why I'm asking the question.
JerryK
@JerryK: Your original pair of questions were too vague to provide any useful information, which is why I provided a non-answer. Please try to be **specific** in what you need to know. Vague questions are difficult to answer.
S.Lott
JerryK: On the contrary, the GIL is generally not a big deal at all. In the general case it's more useful than painful.
Matt Joiner
+3  A: 

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.

phkahler
...unless you use the multiprocessing module, which is pretty easy to do.
detly
...but multiprocessing is no good for fine-grained parallelism.
Gabe
@Gabe: But "fine-grained" parallelism is often over-rated. OS process-level parallelism often works out just.
S.Lott
A: 

Is the new GIL better? If so, how?

Well, it at least replaces op-count switching to proper time-count. This does not increase overall performance (and could even hurt it due to more often switching), but this makes threads more responsive and eliminates cases when ALL threads get locked if one of them uses computation-heavy single op-code (like call to external function which does not release GIL).

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

GIL is complex issue, it should not be viewed as Ultimate Evil. It brings us thread-safety.

As for perl, perl is a) dead, b) too old. Guys at Google are working on bringing LLVM goodies to CPython, which, among others, will improve GIL behavior (no complete GIL removal yet, tho): http://code.google.com/p/unladen-swallow/

Daniel Kluev
+1 for stating fact: Perl is dead. Please don't bring it back
Matt Joiner
-1 for spreading FUD about perl. It's absolutely not dead.
Daenyth