locks

Peter L Hansen peter at engcorp.com
Wed Oct 13 08:52:52 EDT 2004


Cliff Wells wrote:
> On Wed, 2004-10-13 at 14:11 +0200, Diez B. Roggisch wrote:
>>"brutally" serializes (hopefully) all accesses to python data-structures -
> 
> Nope.  It doesn't do this.  For access to items such as integers you are
> probably fine, but for things like lists, dictionaries, class
> attributes, etc, you're on your own.  The GIL only ensures that two
> threads won't be executing Python bytecode simultaneously.  It locks the
> Python *interpreter*, not your program or data structures.
> 
>>so e.g. running several threads, appending to the same list, won't result
>>in messing up the internal list structure causing segfaults or the like.
> 
> True, you won't get segfaults.  However, you may very well get a
> traceback or mangled data.
> 
>>That makes programming pretty easy, at the cost of lots of waiting for the
>>individual threads.
> 
> Threading in Python is pretty easy, but certainly not *that* easy.  

Cliff, do you have any references, or even personal experience to
relate about anything on which you comment above?

In my experience, and to my knowledge, Python threading *is*
that easy (ignoring higher level issues such as race conditions
and deadlocks and such), and the GIL *does* do exactly what Diez
suggests, and you will *not* get tracebacks nor (again, ignoring
higher level issues) mangled data.

You've tentatively upset my entire picture of the CPython (note,
CPython only) interpreter's structure and concept.  Please tell
me you were going a little overboard to protect a possible
newbie from himself or something.

-Peter



More information about the Python-list mailing list