If I run the following code, it would run the print("a") for every time that the pool.map runs.
from multiprocessing import Pool
from os import getpid
print("a")
def double(i):
print("I'm process", getpid())
return i * 2
if __name__ == '__main__':
with Pool() as pool:
result = pool.map(double, [1, 2, 3, 4, 5])
print(result)
Normally this wouldn't be an issue, but in the code that I want to implement multiprocessing in has a long start up time which makes multiprocessing take a long time to get the result, which cancels out the time save of using multiprocessing. So is there a way to make it run only the function in parallel and not the entire file?