Need help in updating a global variable by a thread

dedalusenator at gmail.com dedalusenator at gmail.com
Wed Oct 17 14:48:08 EDT 2007


Hello Folks,

My first posting here and I am a stuck in figuring out the exact way
to update a global variable from within a function that doesnt return
any value (because the function is a target of the thread and I dont
know how exactly return would work in such a case). I am sure I am
missing something very fundamental here. The essential pieces of my
code that cause the problem would be something like this:
---------------------------------------------
lookuptab = {'1.9.7.3':'Bangkok','1.9.60.3':'Sydney'}

results = {}

for val in lookuptab.values():
    results[val]=0

def testt(loc):
       global results
       results[loc] = 1
       return results[loc]

for x in lookuptab.values():
      thread = threading.Thread(target=testt,args=(x))
      thread.start()
print results
-------------------------------------------------------

results contain 0 instead of 1. Any help clearing my block is greatly
appreciated.

-Stephen




More information about the Python-list mailing list