[Tutor] Changing instance attributes in different threads
Kent Johnson
kent37 at tds.net
Tue Feb 7 00:34:18 CET 2006
Bernard Lebel wrote:
> Example:
>
> - Class instance Bernard has attribute "name", whose value is "bernard".
> - A function in a thread tests the value of "name". If "name" ==
> "bernard", do nothing.
> - A function in another thread, for some reason, changes "name" to "bob".
> - The first function, few moments later, tests again the value of
> "name". It see that the value has changed from "bernard" to "bob", and
> this change causes the function to take an action.
>
> Is that what you mean by "invoking" code?
No, it's not what I meant, I was talking about constructs that can cause
an assignment like self.x = 1 to directly call code that you wrote. It
sounds like you are not doing that.
It sounds like you have some attributes that you are using as flags to
allow one thread to control another. There are definitely some pitfalls
here. You probably want to use threading.Condition or Queue.Queue to
communicate between the threads. Can you give more details of what you
are trying to do?
Kent
More information about the Tutor
mailing list