Python: Writing to a single file with queue while using multiprocessing Pool
Multiprocessing pools implement a queue for you. Just use a pool method that returns the worker return value to the caller. imap works well: import multiprocessing import re def mp_worker(filename): with open(filename) as f: text = f.read() m = re.findall(“x+”, text) count = len(max(m, key=len)) return filename, count def mp_handler(): p = multiprocessing.Pool(32) with open(‘infilenamess.txt’) … Read more