atomic operations

Richard Jones rjones at ekit-inc.com
Mon Jan 21 21:30:47 EST 2002


On Tue, 22 Jan 2002 13:17, Lei Chen wrote:
> Hi,
>
>
> Newbie question:
>
> 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...

The function call is atomic, but the assignment is not. The bytecode (use the 
"dis" module to get this) is:

        LOAD_GLOBAL         0 (L)
        LOAD_ATTR           1 (pop)
        CALL_FUNCTION       0
        BUILD_LIST          1
        LOAD_GLOBAL         0 (L)
        LOAD_CONST          1 (0)
        STORE_SLICE+2  

L.pop() is the first three bytecodes.


     Richard




More information about the Python-list mailing list