Thread safetyness in Python

Michael Hudson mwh at python.net
Wed Jul 3 10:02:39 EDT 2002


John Goerzen <jgoerzen at complete.org> writes:

> Hi,
> 
> I have some questions about what is thread-safe in Python.  Can someone tell
> me whether each of the following are thread-safe:

I'm not a thread expert, but these are my answers:

> 1. a = a + 1

No.  a += 1 would be, though (I'm fairly sure).  Assuming a.__add__
isn't written in Python...

> 2. a = a + 2

No.  a += 2, again.

> 3. list.append(x)

Yes.

> 4. list.remove(x)

Yes.

> 5. del(list[0])

Yes.

Cheers,
M.

-- 
  Strangely enough  I saw just such a beast at  the grocery store
  last night. Starbucks sells Javachip. (It's ice cream, but that
  shouldn't be an obstacle for the Java marketing people.)
                                         -- Jeremy Hylton, 29 Apr 1997



More information about the Python-list mailing list