[Python-Dev] PyFAQ: thread-safe interpreter operations (original) (raw)
Jean-Paul Calderone exarkun at divmod.com
Tue Nov 21 03:53:04 CET 2006
- Previous message: [Python-Dev] PyFAQ: thread-safe interpreter operations
- Next message: [Python-Dev] PyFAQ: thread-safe interpreter operations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, 20 Nov 2006 23:55:42 +0100, ""Martin v. Löwis"" <martin at v.loewis.de> wrote:
Fredrik Lundh schrieb:
the FAQ contains a list of "atomic" operation, and someone recently asked whether += belongs to this group. In general, += isn't atomic: it may invoke add or iadd on the left-hand side, or radd on the right-hand side.
From your list, I agree with Josiah Carlson's observation that the examples you give involve separate name lookups (e.g. L.append(x) loads L, then fetches L.append, then loads x, then calls apped, each in a single opcode); the actual operation is atomic. If you only look at the actual operation, the these aren't atomic: x.field = y # may invoke setattr, may also be a property D[x] = y # may invoke x.hash, and x.eq I'm uncertain whether D1.update(D2) will invoke callbacks (it probably will).
Quite so:
>>> class X:
... def __del__(self):
... print 'X.__del__'
...
>>> a = {1: X()}
>>> b = {1: 2}
>>> a.update(b)
X.__del__
>>>
Jean-Paul
- Previous message: [Python-Dev] PyFAQ: thread-safe interpreter operations
- Next message: [Python-Dev] PyFAQ: thread-safe interpreter operations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]