编程语言
首页 > 编程语言> > python Parallel delayed 示例

python Parallel delayed 示例

作者:互联网

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)

结果:

标签:__,count,示例,python,delayed,Parallel,print,cpu
来源: https://www.cnblogs.com/iuyy/p/14056424.html