Is python memory shared between theads?

sjdevnull at yahoo.com sjdevnull at yahoo.com
Fri Dec 1 16:31:22 EST 2006


Wesley Henwood wrote:
> So I declare a variable named A in thread1, in script1.py.  I assign
> the value of 2.5 to A.  I then run script2.py in thread2.  Script2.py
> assigns the value of 5.5 to a variable named A.  Now, when thread1
> resums execution, I see that A = 5.5, rather than 2.5 as I expected.
>
> Is this normal behavior?

Yes.  In fact, sharing memory is the whole reason threads exist.  Use
processes in the (more common) case where you don't want memory
sharing, use threads when you do.




More information about the Python-list mailing list