processes=4 means that multiprocessing starts a pool with four workflows and sends work items to them. Ideally, if you support it, i.e. You have four cores, or workers are not fully attached to the processor, 4 work items will be processed in parallel.
I do not know the implementation of multiprocessing, but I think that the do results will be cached internally even before you read them, i.e. The fifth element will be calculated as soon as any process is completed with the element from the first wave.
If the best way depends on the type of your data. How many files are there in total that require processing, how large are the summary objects, etc. If you have many files (say, more than 10 thousand), Their admission may be an option through
it = pool.imap_unordered(do, glob.iglob(aglob), chunksize=100)
Thus, the work item is not a single file, but 100 files, and the results are also reported in batches of 100. If you have many work items, then the pieces reduce the overhead of etching and pasting the result objects.
source share