Original Sources:
Used in this file:
Δttention:
multiprocessing.Pool().map() does not accept lambda functions
~ Ex.:
import multiprocessing
a = (1,2,3,4,5,6,7)
def mappiing(x):
import time.sleep
time.sleep(1)
return x+1
pool = multiprocessing.Pool()
b = pool.map(mappiing,a)
#Should take 7 seconds it takes WAY LESS,
#because the map is beind executed
#in parallel with multiple processesOptional: How many processes are runned at the same time:
import multiprocessing
pool = multiprocessing.Pool(processes = 4)Optional: How may task can a process take before starting a new process
import multiprocessing
pool = multiprocessing.Pool(maxtasksperchild = 10)
# A process (~es. process number 17403) does 10 task
# (~es.: executes 10 mapping from start to end than)
# kills itself and a new process (~es.: 17408) starts