【发布时间】:2021-03-08 03:39:06
【问题描述】:
我有一个非常大的字典列表,其中键是(string、float、string)的三倍,其值又是列表。
cols_to_aggr 基本上是list(defaultdict(list))
我希望我不仅可以将列表索引i 传递给我的函数_compute_aggregation,而且还可以只传递该索引包含的数据,即cols_to_aggr[i],而不是整个数据结构cols_to_aggr,并且必须获得我的并行函数中的小块。
这是因为问题是整个数据结构的这种传递导致我的池完全没有效率地耗尽了我所有的内存。
with multiprocessing.Pool(processes=n_workers, maxtasksperchild=500) as pool:
results = pool.map(
partial(_compute_aggregation, cols_to_aggr=cols_to_aggr,
aggregations=aggregations, pivot_ladetag_pos=pivot_ladetag_pos,
to_ix=to_ix), cols_to_aggr)
def _compute_aggregation(index, cols_to_aggr, aggregations, pivot_ladetag_pos, to_ix):
data_to_process = cols_to_aggr[index]
为了解决我的内存问题,我尝试设置maxtasksperchild,但没有成功,我不知道如何以最佳方式设置它。
【问题讨论】:
标签: python python-3.x functional-programming python-multiprocessing