theads & global namespaces
Taylor Anderson
andersdt at notes.cba.ufl.edu
Wed Jun 30 14:06:01 EDT 1999
Greetings all,
I am trying to share globals between threads. Is is possible for me to
share globals between threads that call functions from different
modules? Thus far I have had little success. I ask this question
because I would prefer not to put all my code in one module.
For example, I have 2 .py files: a.py and b.py. b.py contains the
function ('foo()') to be executed under the new thread, as well as the
global variable 'x'. a.py contains the call to
start_new_thread(foo,()). a.py also tries to use the global variable x.
=========================================
b.py
x = 0
def foo():
global x
x = x + 1
=========================================
a.py
from b.py import *
if __name__ == '__main__':
start_new_thread(foo, ())
while 1:
if x != 0:
print x
=========================================
So far, my code in a.py does not detect any change in x. Any
suggestions for a workaround?
Many thanks,
Taylor
More information about the Python-list
mailing list