I asked a related but very general question earlier (see especially this response).
This question is very specific. This is all the code I care about:
result = {}
for line in open('input.txt'):
key, value = parse(line)
result[key] = value
The function parse is completely self-contained (i.e., doesn’t use any shared resources).
I have Intel i7-920 CPU (4 cores, 8 threads; I think the threads are more relevant, but I’m not sure).
What can I do to make my program use all the parallel capabilities of this CPU?
I assume I can open this file for reading in 8 different threads without much performance penalty since disk access time is small relative to the total time.
cPython does not provide the threading model you are looking for easily. You can get something similar using the
multiprocessingmodule and a process poolsuch a solution could look something like this: