I have some code that looks like this:
for photo in photoInfo:
if not('url' in photo):
raise Exception("Missing URL: " + str(photo) + " in " + str(photoInfo))
sizes = getImageSizes(photo['url'])
photo.update(sizes)
It might not be obvious, but the code performs a mix of high-latency I/O (opening a remote URL) and moderately CPU-intensive process (parsing image and extracting size) for each photo.
What's the easiest way to parallelize this code?
What I have tried so far
I found this code in the answer to another, more complex question, but I'm having a hard time mapping it back to my much simpler use-case:
from itertools import product
from multiprocessing import Pool
with Pool(processes=4) as pool: # assuming Python 3
pool.starmap(print, product(range(2), range(3), range(4)))