from joblib import Parallel, delayed
def get_pid(p_num):
import os
import time
time.sleep(10)
return "%d_%d" % (p_num, os.getpid())
# function delayed to warp (proxy) a parallel function
tasks = [delayed(get_pid)(_) for _ in range(100)]
# use 5 progress to run tasks
ret = Parallel(n_jobs=5)(tasks)
print(ret)