basic python threading question

Tom nospam at nospam.com
Fri Sep 29 13:21:38 EDT 2000


"Aahz Maruch" <aahz at panix.com> wrote in message
news:8r2hdl$6rr$1 at panix6.panix.com...
> In article <q_IA5.42927$dZ2.15588642 at news3.rdc1.on.home.com>,
> Tom <nospam at nospam.com> wrote:
> >
> >This would be a problem for threading, unless all atomic objects are
> >thead-safe.  Now, all atomic objects appear to me to be immutable.  Are
> >immutable objects inherently thread-safe in Python (even if the ref count
> >change)?
>
> Yes, immutable objects are thread-safe.  Remember that assignment in
> Python is a binding operation, not a modification operation.

Thanks for the answer.

But, even an immutable object has its reference count modified by a binding
operation.  And this sounds like a problem to me, since (quoting from
section 8.1 of  API Ref):

"when two threads simultaneously increment the reference count of the same
object, the reference count could end up being incremented only once instead
of twice. "

I'm finding threading on Python to be more complicated than threading in C.
It also seems that threading in any interpreted environment must have a
fairly heavy overhead, and so is best avoided.

Tom.

> --
>                       --- Aahz (Copyright 2000 by aahz at pobox.com)
>
> Androgynous poly kinky vanilla queer het    <*>
http://www.rahul.net/aahz/
> Hugs and backrubs -- I break Rule 6
>
> "Perhaps God rewards martyrs, but life seldom does..." --Ulrika O'Brien





More information about the Python-list mailing list