atomic operations

Aahz Maruch aahz at
Tue Jan 22 03:45:29 CET 2002

In article <de6c123c.0201211817.1cf8ec81 at>,
Lei Chen <llchen223 at> wrote:
>Let say that L = [1,2,3]
>I read in the FAQ that L.append(4) and L.pop() are atomic operations
>under Python.  Are L.remove(2) and L[:0] = [L.pop()] atomic operations
>too?  The FAQ says each bytecode instruction is atomic, so I guess the
>question is whether each of the above operations are compiled as a
>single bytecode instruction...

If you really want to know, use the dis module.  But it's poor practice
to rely on Python operations being atomic, because if L ever ends up
being something other than a pure-internal Python list(), you could be
wrong.  If this is in the context of a threaded application, use an
RLock() to make operations atomic.
                      --- Aahz  <*>  (Copyright 2002 by aahz at

Hugs and backrubs -- I break Rule 6       
Androgynous poly kinky vanilla queer het Pythonista   

"I support family values -- Addams family values"

More information about the Python-list mailing list