elsefactors [valuereturn factors if __name__ ='__main__'pool pool(to_factor random randint( for in range( results pool map(prime_factorto_factorfor valuefactors in zip(to_factorresults)print("the factors of {are {}format(valuefactors)let' focus on the parallel processing aspects as the brute force recursive algorithm for calculating factors is pretty clear we first construct multiprocessing pool instance by defaultthis pool creates separate process for each of the cpu cores in the machine it is running on the map method accepts function and an iterable the pool pickles each of the values in the iterable and passes it into an available processwhich executes the function on it when that process is finished doing it' workit pickles the resulting list of factors and passes it back to the pool once all the pools are finished processing work (which could take some time)the results list is passed back to the original processwhich has been waiting patiently for all this work to complete it is often more useful to use the similar map_async methodwhich returns immediately even though the processes are still working in that casethe results variable would not be list of valuesbut promise to return list of values later by calling results get(this promise object also has methods like ready()and wait()which allow us to check whether all the results are in yet alternativelyif we don' know all the values we want to get results for in advancewe can use the apply_async method to queue up single job if the pool has process that isn' already workingit will start immediatelyotherwiseit will hold onto the task until there is free process available pools can also be closedwhich refuses to take any further tasksbut processes everything currently in the queueor terminatedwhich goes one step further and refuses to start any jobs still on the queuealthough any jobs currently running are still permitted to complete