python gevent使用例子

 

python gevent使用例子

from gevent.pool import Pool

POOL_SIZE = 100

def process(func, param1_list, param2_list)
    stat = {}
    pool = Pool(POOL_SIZE)
    results = pool.imap_unordered(func, param1_list, param2_list)
    pool.join()
    # 处理结果
    for value in results:
        stat.update(value)
    return stat

def add(a, b):
return {a: a+b}

print(process(add, [1,2,3], [3,4,5]))
# {1: 4, 2: 6, 3: 8}

 

posted @ 2019-04-17 17:35  道以万计  阅读(1158)  评论(0编辑  收藏  举报