Are Lists thread safe?

Duncan Booth duncan.booth at invalid.invalid
Mon Mar 12 05:02:25 EDT 2007


"Gabriel Genellina" <gagsl-py2 at yahoo.com.ar> wrote:

> INPLACE_ADD would call MyList.__iadd__ which you have wrapped. But you
>  have a race condition between that moment and the following
> STORE_ATTR, a  context switch may happen in the middle.
> 
> It may not be possible to create an absolutely thread-safe list
> without  some help on the client side. (Comments, someone?)

The list itself can be thread safe quite easily, but if the namespace from 
which you reference it is shared between threads you would have to protect 
the namespace as well, or avoid using in-place operators.

The rebinding is a mutation on the namespace rather than the object, so 
that is what you have to protect.



More information about the Python-list mailing list