decorators vs GIL

Anthony Baxter anthonybaxter at gmail.com
Sun Aug 8 22:50:29 EDT 2004


On Sun, 8 Aug 2004 22:18:45 -0400 (EDT), mudd at vex.net <mudd at vex.net> wrote:
> Is there anything else that Python doesn't do well that we should appreciate?

I wouldn't go so far as to say that we should _appreciate_ the GIL, more that
it ends up being not so much of a problem because Python gives us many, 
many better ways to do things than with threads. 

About the only actual issue with the GIL is that it stops a single
Python interpreter
from taking better advantage of multiple CPUs in a box. But, if you code with a
knowledge of the GIL, this is easy enough to work around.

The advantages of the GIL is that the implementation is far more robust, and far
less overhead is wasted in lots of tiny little locks. In addition, it
means that a single
python instruction is guaranteed to be thread safe - so in a threaded app I can
do something like 
    somedict['foo'] = 1
without having to wrap access in a lock to make sure I don't end up with a
hosed dictionary. Once you end up with lots of little locks in a threaded 
application, madness is surely not far away.

Anthony



More information about the Python-list mailing list