basic python threading question

Tom nospam at nospam.com
Thu Sep 28 16:42:48 EDT 2000


"matt" <matt at virtualspectator.com> wrote in message
news:mailman.970172746.8175.python-list at python.org...
> What is wrong with doing a deep copy?

I was planning to do a deep copy, but then I looked at the code for it and
found that it didn't really copy atomic objects.  I figured this is because
you can't really make a copy of an atomic object - until you change the
copies' value, the interpreter would just double up on the original value.

> And I thought atomic object were thread safe by definition, in so far as
only
> one processing cycle is required to execute it.  If something is not
thread
> safe then it needs to be atomic such that in the more abstract sense a
call on
> it will have to go to completion before anything else gets a chance to use
it.

For 'processing cycle' I assume you mean Python byte code, and I'm not sure:
does it only take one byte code to complete an operation on an atomic
object?  If so then I guess I've got my answer.

> The other thing I am confused about is that I never really thought the
object
> itself could be thread-safe.  Isn't thread safety only to do with how you
> handle the methods that use an object, such that any methods that change
an
> object, and these should be part of the definition of the object, are the
> things that are atomic.

By a thead-safe object, I meant one that I could perform arbitrary
operations on without having to lock it.  If I can't make a real copy of it,
then I hope it is 'thread-safe', or I'll have to do a lot of locking.

But then again, I'm new to threading in Python so I could be wrong about all
this.

Tom.

>
> Matt
>
> On Fri, 29 Sep 2000, Tom wrote:
> > I decided to give a thread its own copy of some data.  But I gather that
it
> > is impossible to create a seperate copy of an atomic object (because the
> > implementation is free to make both names bind to the same object).
> >
> > 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)?
> >
> > Thanks,
> >
> > Tom.
> >
> >
> >
> >
> > --
> > http://www.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list