future_list = []
result = {"weight_1":[],"weight_2":[]}
with ProcessPoolExecutor(max_workers=10) as exec:
for weight in weight_lists:
try:
future = exec.submit($func_name,$para)
future_list.append(future)
except Exception as e:
print(e)
for future in as_completed(future_list):
try:
info = future.result()
print(idx,info['weight'],info['exec_time'] )
result['weight_1'].append(info['weight'])
result['weight_2'].append(info['weight'])
except Exception as e:
print(e)
pd.DataFrame(result).to_excel(info_path + "/idx=" + str(idx) + ".xlsx")
python多进程处理(ProcessPoolExecutor)
于 2024-03-12 12:41:12 首次发布
文章介绍了一种利用进程池和异步执行在Python中处理`future_list`中的任务,计算权重值和记录执行时间的方法,并将结果整理成Excel表格。
1492

被折叠的 条评论
为什么被折叠?



