1、代码
# -*- coding: utf-8 -*-
from multiprocessing import Pool,Manager,queues
import multiprocessing,queue,time
def test_fun(test_param, i):
print(i)
return [test_param, i]
if __name__=="__main__":
max_num = 100
process_num = 10 #进程数量
pool = Pool(process_num) # 创建进程池
test_param = 'test'
args = [[test_param, i+1] for i in range(max_num )] # 根据进程池数据量配置进程参数
res = pool.starmap(test_fun, args) # starmap 同步并行处理
# res = pool.starmap_async(test_fun, args) # starmap_async 异步并行处理
print(res) # 函数返回结果
pool.close() # 关闭线程池,不再接受新的进程
pool.join() # 阻塞主进程,等待子进程退出