atomic operations

Aahz Maruch aahz at panix.com
Mon Jan 21 21:45:29 EST 2002


In article <de6c123c.0201211817.1cf8ec81 at posting.google.com>,
Lei Chen <llchen223 at hotmail.com> 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 pobox.com)

Hugs and backrubs -- I break Rule 6                 http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het Pythonista   

"I support family values -- Addams family values" --www.nancybuttons.com



More information about the Python-list mailing list