Python3 多线程处理列表

from multiprocessing.pool import ThreadPool

声明方法

def get_num(num):
    return num-1;

多线程处理

data = [1,2,3,4,5,6,7,8]

_thread_pool = ThreadPool(4)
results = _thread_pool.map(get_num, data)
_thread_pool.close()

结果数组索引和列表对应

print(results)

[0,1,2,3,4,5,6,7]

评论已关闭。