断管:使用来自多处理P的映射

2024-05-14 23:11:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在HPC中使用多处理来加速我的代码。它运行正常,但我添加了一些计算,突然它开始发布这个错误。我运行它没有多重处理,它很好。在

前20个函数的执行与多处理配合得很好,但之后就开始滚雪球了,这个错误越来越频繁地出现。在

在日志中写到“在某个点超过了步骤内存限制”和“原因:'RuntimeError('maximum recursion depth when calling a Python object',)'”

import os
from multiprocessing import Pool

def eigencen(filename):
    --DO complicated stuff here--

for f in os.listdir(FOLDER):
    list_fn.extend([f])

def evaluation(f_list):
    return list(Pool(processes=28).map(eigencen, f_list))
evaluation(list_fn)

我能修好它吗?如果不进行多重处理,它将永远无法运行。在


Tags: 函数内存代码importosdef错误步骤
1条回答
网友
1楼 · 发布于 2024-05-14 23:11:23

尝试使用concurrent.futures模块:

from concurrent import futures

def evaluation(f_list):
    with futures.ProcessPoolExecutor() as pool:
        return pool.map(eigencen, f_list)

相关问题 更多 >

    热门问题