I have the following setup:
results = [f(args) for _ in range(10**3)]
But, f(args)it takes a lot of time to calculate. Therefore, I would like to throw multiprocessing on it. I would like to do this:
pool = mp.pool(mp.cpu_count() -1)
results = [pool.apply_async(f, args) for _ in range(10**3)]
It’s clear that I don’t have 1000 processors on my computer, so my concern:
Does the above call cause 1000 processes simultaneously competing for the processor time or 7 processes working simultaneously, iteratively calculating the next f(args)one when the previous call ends?
I suppose I could do something like pool.async_map(f, (args for _ in range(10**3)))to get the same results, but the purpose of this post is to understand the behaviorpool.apply_async
source
share