Are python objects thread-safe?
gagsl-py2 at yahoo.com.ar
Tue Dec 23 19:00:08 CET 2008
En Tue, 23 Dec 2008 11:30:25 -0200, Duncan Booth
<duncan.booth at invalid.invalid> escribió:
> Aaron Brady <castironpi at gmail.com> wrote:
>> Th.1 Th.2
>> You are saying that if 'a=Z' interrupts 'a=Y' at the wrong time, the
>> destructor for 'X' or 'Y' might not get called. Correct? In serial
>> flow, the destructor for X is called, then Y.
> No, the destructors will be called, but the destructors can do pretty
> anything they want so you can't say the assignment is atomic. This isn't
> actually a threading issue: you don't need multiple threads to experience
> werid issues here. If you do strange things in a destructor then you can
> come up with confusing code even with a single thread.
A simple example showing what you said:
py> class A:
... def __del__(self):
... global a
... a = None
py> a = A()
py> a = 3
py> print a
More information about the Python-list