Aahz aahz at
Sat Feb 22 03:36:33 CET 2003

In article <878dc260.0302210733.58c4f521 at>,
Renzo Tomaselli <renzo.tomaselli at> wrote:
>assume I have a Python obj instance in a web application after
>The point is: can I assume that accessing local variables within a
>method of such instance is thread-safe, e.g. syncronized by the
>interpreter against concurrent invokations by multiple threads (e.g.
>multiple web clients) ?
>In a C++ environment, such automatic variables would be on the stack,
>e.g. they would exist per-thread. But in Python they are in the heap,
>so I dont't know about concurrency.

Because Python is so introspective, nothing is completely safe.
However, if your scope is inside a method, any objects created within
that method call are essentially safe.  What may not be safe is
accessing objects passed in to the method (if they're mutable), and it
may not be safe to access "self" if multiple threads contain references
to that object.

In other words, while the objects are created on the heap, the use of
local names as the only bindings for those objects makes it safe.
Aahz (aahz at           <*>

Register for PyCon now!

More information about the Python-list mailing list