Eamonn

人生苦短,我用Python

· 默认分类 · · 159次浏览

python进程池multiprocessing.Pool和线程池

from multiprocessing.dummy import Pool as ThreadPool

def bpool(callback,lists,threadNum=10):
    tpool=ThreadPool(threadNum)
    res=tpool.map(callback,lists)
    tpool.close()
    tpool.join()
    return res

def sleep(a):
    eamonn.sleep(3)
    print(a)

bpool(sleep,['1','2','3'])
评论 (0条)