from multiprocessing import cpu_count from joblib import Parallel, delayed def func(in_put): return in_put ** 3 if __name__ == '__main__': cpu__count = cpu_count() with Parallel(n_jobs=cpu__count) as parallel: out0 = parallel(delayed(func)(i) for i in range(10)) print(out0) print("------------------------------------------") out1 = [i**3 for i in range(10)] print(out1)
结果: