python3 多线程

from multiprocessing import Pool

def f(x):
    sleep(1)
    print(1)
    sleep(1)
    print(2)
    return x*x

if __name__ == '__main__':
    plist = [1, 2, 3, 4, 5, 6]
    with Pool(6) as p:
        print(p.map(f, plist))
        # map(self, func, iterable, chunksize)

 

posted on 2021-06-29 17:24  Karlkiller  阅读(31)  评论(0编辑  收藏  举报

导航