I'm trying to read multiple lines of a file at once in order to separate those lines into two separate lists. The cleanLine function essentially takes in the line that it is fed and cleans it, returning a line with no whitespaces. Right now my code compiles and returns the same results it did without multiprocessing, however, the overall runtime of the script has not improved so I am unsure if it is actually spawning multiple processes at once or if it is just doing one at a time still. In this specific case I'm not really sure how to tell if its actually creating multiple processes or just one. Is there any reason this portion of the script does not run any faster or am I doing this incorrectly? Any help or feedback would be greatly appreciated.
Snippet of the code:
import multiprocessing
from multiprocessing import Pool
filediff = open("sample.txt", "r", encoding ="latin-1")
filediffline = filediff.readlines()
pos = []
neg = []
cpuCores = multiprocessing.cpu_count() - 1
pool = Pool(processes = cpuCores)
for line in filediffline:
result = pool.apply_async(cleanLine, [line]).get()
if line.startswith("+"):
pos.append(result)
elif line.startswith("-"):
neg.append(result)
pool.close()
pool.join()