如何修复PyCharm中的Python多处理映射内存错误

如何修复PyCharm中的Python多处理映射内存错误,python,memory,multiprocessing,Python,Memory,Multiprocessing,我最近换了一台更强大的电脑,我的代码开始产生内存错误,在以前的配置中没有任何问题。 我试图将PyCharm VM选项中的值增加到-Xms32768m-Xmx65536m,但没有效果。 将映射更改为imap可以使程序正常工作。有人知道是什么导致内存错误以及如何修复它吗 from multiprocessing import Pool def one_round(i): return i def batch(iterable, n=1): current_batch = []

我最近换了一台更强大的电脑,我的代码开始产生内存错误,在以前的配置中没有任何问题。 我试图将PyCharm VM选项中的值增加到-Xms32768m-Xmx65536m,但没有效果。 将映射更改为imap可以使程序正常工作。有人知道是什么导致内存错误以及如何修复它吗

from multiprocessing import Pool


def one_round(i):
    return i


def batch(iterable, n=1):
    current_batch = []
    for item in iterable:
        current_batch.append(item)
        if len(current_batch) == n:
            yield current_batch
            current_batch = []
    if current_batch:
        yield current_batch


def one_batch(batch):
    with open(f"Batches_{batch[0]//10**6}.txt", "w") as outputfile:
        for i in batch:
            outputfile.write(str(one_round(i))+"\n")
    return


if __name__ == '__main__':
    p = Pool(13)
    R = 10 ** 9
    results = p.map(one_batch, batch(range(R), 10*6))
    p.close()
    p.join()
回溯(最近一次呼叫最后一次):
文件“…\Test.py”,第31行,在
结果=p.map(一个批次,批次(范围(R),10*6))
文件“…\anaconda3\envs\…\lib\multiprocessing\pool.py”,第364行,在地图中
返回self.\u map\u async(func、iterable、mapstar、chunksize).get()
文件“…\anaconda3\envs\…\lib\multiprocessing\pool.py”,第475行,在异步映射中
iterable=列表(iterable)
文件“…\Tests\Test.py”,第11行,成批
对于iterable中的项目:
记忆者
Traceback (most recent call last):
  File "...\Test.py", line 31, in <module>
    results = p.map(one_batch, batch(range(R), 10*6))
  File "...\anaconda3\envs\...\lib\multiprocessing\pool.py", line 364, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "...\anaconda3\envs\...\lib\multiprocessing\pool.py", line 475, in _map_async
    iterable = list(iterable)
  File "...\Tests\Test.py", line 11, in batch
    for item in iterable:
MemoryError