posible generar una variable dinámica?

I want to call a function, that starts a subprocess, like that:

processrrd = Popen(args1, stdout=PIPE, stderr=PIPE, env={'LANG':'de_DE@euro','TZ':'Europe/Berlin'})
outputrrd = processrrd.communicate()
(output, error) = outputrrd

Now I want to use multiprocessing.pool in order to paralize the worker. The problem is that the variable outputrrd ist overwritten by the last Popen. So, is it possible to create a specific variable (processrrd), like name1_processrrd?

Saludos. Stefan

UDPATE: tried this one, but the output of the processes are the same....:

processrrd = []
processrrd.append((hostgroup+'_processrrd'))
print processrrd
    for name in processrrd:
        print name
        name = Popen(args1, stdout=PIPE, stderr=PIPE, env={'LANG':'de_DE@euro','TZ':'Europe/Berlin'})
        outputrrd = name.communicate()
    (output, error) = outputrrd

preguntado el 31 de julio de 12 a las 15:07

Generating variables at runtime is possible, but discouraged. Use a list. -

1 Respuestas

Without even considering whether multiprocessing gives you any better approaches (I'm guessing it does, but don't know it very well at all), you'd be better off storing each handle in some sort of data structure, such as a dict o con una list, p.ej,

# TODO Use name and key that works for you.
my_processes['de_DE@euro'] = Popen(args1, stdout=PIPE, stderr=PIPE, env={'LANG':'de_DE@euro','TZ':'Europe/Berlin'})

Respondido 31 Jul 12, 15:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.