theads & global namespaces

Taylor Anderson Taylor.Anderson at
Wed Jun 30 12:06:01 CEST 1999

From: Taylor Anderson <andersdt at>

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: and contains the
function ('foo()') to be executed  under the new thread, as well as the
global variable 'x'. contains the call to
start_new_thread(foo,()). also tries to use the global variable x.


x = 0

def foo():
   global x
   x  = x + 1


from import *

if __name__ == '__main__':

    start_new_thread(foo, ())
    while 1:
        if x != 0:
            print x


So far, my code in does not detect any change in x.  Any
suggestions for a workaround?

Many thanks,


More information about the Python-list mailing list