Pool.mapand ify is passed to them, so your generator will always be fully implemented before processing even starts .Pool.map_async listiterable
Various functions Pool.imap*seem to handle inputs as generators, so you can change:
results = pool.map(process_file, (open(path+part,'rb').read() for part in os.listdir(path)))
in
results = list(pool.imap(process_file, (open(path+part,'rb').read() for part in os.listdir(path))))
, AFAICT, , , ; , , IPC, , - -.
(, , , , ). , IPC, , , ; , . , :
def process_file(path):
with open(path, 'rb') as f:
file_string = f.read()
... same as before ...
return processed_file
pool = Pool(processes=4)
path = 'some/path/'
results = pool.imap(process_file, (os.path.join(path, part) for part in os.listdir(path)))