相关疑难解决方法(0)

Python多处理 - 调试OSError:[Errno 12]无法分配内存

我面临以下问题.我正在尝试并行化一个更新文件的函数,但我无法启动Pool()因为一个OSError: [Errno 12] Cannot allocate memory.我开始在服务器上四处看看,这并不像我使用旧的,弱的/实际内存.见htop: 在此输入图像描述 此外,free -m显示除了大约7GB的交换内存外,我还有足够的RAM: 在此输入图像描述 而我正在尝试使用的文件也不是那么大.我将粘贴我的代码(和堆栈跟踪),其中,大小如下:

使用的predictionmatrix数据框占用大约.根据pandasdataframe.memory_usage() 文件geo.geojson为80MB 是2MB

我该如何调试呢?我可以检查什么以及如何检查?感谢您的任何提示/技巧!

码:

def parallelUpdateJSON(paramMatch, predictionmatrix, data):
    for feature in data['features']: 
        currentfeature = predictionmatrix[(predictionmatrix['SId']==feature['properties']['cellId']) & paramMatch]
        if (len(currentfeature) > 0):
            feature['properties'].update({"style": {"opacity": currentfeature.AllActivity.item()}})
        else:
            feature['properties'].update({"style": {"opacity": 0}})

def writeGeoJSON(weekdaytopredict, hourtopredict, predictionmatrix):
    with open('geo.geojson') as f:
        data = json.load(f)
    paramMatch = (predictionmatrix['Hour']==hourtopredict) & (predictionmatrix['Weekday']==weekdaytopredict)
    pool = Pool()
    func = partial(parallelUpdateJSON, paramMatch, predictionmatrix)
    pool.map(func, data)
    pool.close()
    pool.join()

    with …
Run Code Online (Sandbox Code Playgroud)

python linux out-of-memory python-multiprocessing

6
推荐指数
2
解决办法
8026
查看次数