[Baypiggies] GIL for dummies

Shannon -jj Behrens jjinux at gmail.com
Fri Jun 12 23:34:07 CEST 2009

On Fri, Jun 12, 2009 at 1:09 PM, Aahz<aahz at pythoncraft.com> wrote:
> On Fri, Jun 12, 2009, Benjamin Sergeant wrote:
>> I found that on reddit this morning, and it's very interesting for
>> people like me who followed the GIL heated debates without really
>> understanding a single bit ... the paper is very clear and based on
>> one CPU bound program that perform (way) better in a single thread
>> than in two threads (on a MacBook probably with 2 cores).
>> http://www.dabeaz.com/python/GIL.pdf
> This is a good resource, but keep in mind that it's explaining why the
> GIL has problems with CPU-bound threads rather than talking about
> productive ways to write threaded programs in Python.

If you're CPU bound, you can switch to using process pools, perhaps
with the processing module.  If you have some CPU intensive section
that you can translate to C, you may be able to release the GIL in C
before entering that section.

I wrote about such things here: http://www.ddj.com/linux-open-source/206103078

Aahz talked about the GIL here:

At the risk of wandering off topic, I was amazed to see that Scala
lets you use multiple cores, supports Erlang-style concurrency, and
performs far better than Python on a lot of benchmarks.  I'm going to
keep coding Python everywhere I can, but I'll probably think about
using Scala for a certain class of problems.

Happy Hacking!

In this life we cannot do great things. We can only do small things
with great love. -- Mother Teresa

More information about the Baypiggies mailing list