I need to modify a list
by adding some elements at the end from a thread.
This is my code:
def go():
while queueCommand.qsize() > 0:
command = queueCommand.get(False)
res = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, shell=True)
output = res.communicate()
output = str(output)
star = output.find("address") + 8
en = output.find(",")
ip = output[star:en-3]
alist.append(ip) #<================== her i use the liste
if __name__ == '__main__':
with open ("icq.txt","r") as myfile:
text = myfile.read()
end = 0
alist = []
queueCommand = Queue.Queue()
while True:
start = text.find("href=") + 13
if start == 12:
break
end = text.find("/",start)
if text[start:end].find("icq.com") != -1:
hostname="host "+ text[start:end]
queueCommand.put(hostname)
text = text[end:len(text)]
for i in range(10):
threading.Thread(target=go,args=(alist)).start() #<====== i give the list as argument
print alist
The last print statement display an empty list, []
. Any ideas?