I open more Process with python to retrive files via urlib2, I only put the call to the fucntion.
t = Process(target=traer, args=(dir, listado[contador],))
This is the function that call in the process object
def traer(dir,y):
global listado2
try:
file = urllib2.urlopen(dir+y)
nombre=y
output = open('C:/ndfd/degrib/bin/archivos/'+nombre ,'wb')
output.write(file.read())
output.close()
except urllib2.HTTPError, e:
print 'HTTPError = ' + str(e.code)
except urllib2.URLError, e:
listado2.append(y)
print 'URLError = ' + str(e.reason)
This is in root of the archive
if __name__ == '__main__':
global listado
global listado2
listado=[]
listado2=[]
crear_trip(dir,listado)
salida_bath(dir,listado,listado2)
inside salida_bath are inside a loop while that turn on the process.
In the exception I will like append to a global variable called listado2 but this not work, say me that it is undefined listado2.
MY FIX OF THIS PROBLEM FOR ME, change the strategy
create inside the salida_bath
manager = Manager()
listado2 = manager.dict()
put a contador of the process and past the new listado2 to the process
t = Process(target=traer, args=(contador,dir, listado[contador],listado2))
and in traer function change this.
except urllib2.URLError, e:
listado2[contador]=y
print 'URLError = ' + str(e.reason)
check outside that this is working
for x in listado2.values():
listado.append(x)
print listado