Better multithreaded use of Python subprocess.Popen & communicate()?
问题 I'm running multiple commands which may take some time, in parallel, on a Linux machine running Python 2.6. So, I used subprocess.Popen class and process.communicate() method to parallelize execution of mulitple command groups and capture the output at once after execution. def run_commands(commands, print_lock): # this part runs in parallel. outputs = [] for command in commands: proc = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)