stupid thread question

j vickroy jvickroy at sec.noaa.gov
Tue Jun 13 10:09:53 EDT 2000


Would the Event class in the threading module be of use to you?

Michael Vanier wrote:

> Python gurus,
>
> Apologies if this has come up before...
>
> I wrote a little python script using the thread module the other day.  I
> wanted to be able to set a flag in the parent thread that would be read in
> the child thread.  So I set a flag variable (an integer in this case) in the
> parent, created the child thread, and then checked the value of the flag
> every time through a loop in the child thread to see if it had changed.  It
> turns out that the child thread apparently made a copy of the flag, because
> when it changed in the parent it didn't change in the child.
>
> To fix this, I changed the flag to be a list with one integer element.  Now,
> when I change the list element in the parent, the child sees it too.  I
> gather that what this means is that there is a fundamental distinction
> between atomic types like integers and reference types like lists or
> dictionaries.  However, since python treats everything as a reference this
> seems inconsistent to me.  So what I want to know is: what is the cause of
> this behavior, and what is the justification for it?  Or could it be a bug?
>
> FWIW this is on a RH Linux 6.1 system running python 1.6a2 with pthreads (I
> assume).
>
> TIA,
>
> Mike
>
> --------------------------------------------------------------
> Mike Vanier     mvanier at bbb.caltech.edu
> Department of Computation and Neural Systems, Caltech 216-76
> GNU/Linux: We can't lose; we're on a mission from God.




More information about the Python-list mailing list