threads, mutual exclusion, and lists

"Martin v. Löwis" martin at v.loewis.de
Wed Aug 15 18:46:58 EDT 2007


> I have two threads that share a python list. One thread adds to the
> list with append(), the other thread removes items with pop().
> 
> My question is -- are python list operations atomic?

Yes, they are in the current implementation of CPython (all versions).
Notice that not *all* operations are atomic (e.g. .sort() is not),
but both append and pop happen to be atomic (which is primarily because
they don't need to call back to user-defined functions, unlike sort).

It's not a language property, though; things may be different in Jython
or IronPython.

Regards,
Martin



More information about the Python-list mailing list