1

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?

Regards. 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
1
  • 3
    Generating variables at runtime is possible, but discouraged. Use a list.
    – Fred Foo
    Jul 31, 2012 at 14:35

1 Answer 1

1

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 or a list, e.g.,

# 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'})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.