I have a generator that downloads files from FTP. I want to run these in parallel, without exhausting the generator together. I want the generator to lazily be evaluated. Is this possible in Python 2?
def parse_and_load(filename):
raw_records, exchange_data = parser.parse(filename)
loader.load(raw_records, exchange_data)
with closing(mp.Pool(4)) as pool:
pool.map(parse_and_load, downloader.get_files(self.date))
Instead of downloading 4 files and processing them in parallel, the above code is evaluating the whole generator first and then calling parse and load in parallel.