Mailing List Archive

parallel subprocess.getoutput
Hello,

I wrote the following code for using egrep on many large files:

MY_DIR = '/my/path/to/dir'
FILES = os.listdir(MY_DIR)

def grep(regex):
i = 0
l = len(FILES)
output = []
while i < l:
command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' +
FILES[i]
result = subprocess.getoutput(command)
if result:
output.append(result)
i += 1
return output

Yet, I don't think that the files are searched in parallel. Am I
right? How can I search them in parallel?

Jaroslav
--
http://mail.python.org/mailman/listinfo/python-list
Re: parallel subprocess.getoutput [ In reply to ]
Sorry, for code-historical reasons this was unnecessarily complicated.
Should be:


MY_DIR = '/my/path/to/dir'
FILES = os.listdir(MY_DIR)


def grep(regex):
output = []
for f in FILES:
command = "egrep " + '"' + regex + '" ' + MY_DIR + '/' + f
result = subprocess.getoutput(command)
if result:
output.append(result)
return output
--
http://mail.python.org/mailman/listinfo/python-list