Is python memory shared between theads?
Daniel Dittmar
daniel.dittmar at sap.com
Fri Dec 1 12:21:21 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?
Not if this is all you are doing. A variable A in script1.py and a
variable A in script2.py are completely different, even when running in
the same thread.
But if you're running script1.py and script2.py by calling execfile or
exec and you pass the same dictionary as the globals argument to
execfile, then the two scripts would share the global namespace.
Variables of the same name would really be the same variable.
Daniel
More information about the Python-list
mailing list