小编Ise*_*sea的帖子

为什么我的循环在每次迭代时需要更多内存?

我试图减少我的python 3代码的内存要求.现在for循环的每次迭代都需要比最后一次更多的内存.

我写了一小段与我的项目具有相同行为的代码:

import numpy as np
from multiprocessing import Pool
from itertools import repeat


def simulation(steps, y):  # the function that starts the parallel execution of f()
    pool = Pool(processes=8, maxtasksperchild=int(steps/8))
    results = pool.starmap(f, zip(range(steps), repeat(y)), chunksize=int(steps/8))
    pool.close()
    return results


def f(steps, y):  # steps is used as a counter. My code doesn't need it.
        a, b = np.random.random(2)
        return y*a, y*b

def main():
    steps = 2**20  # amount of times a random sample is taken
    y = np.ones(5) …
Run Code Online (Sandbox Code Playgroud)

python memory python-multiprocessing

8
推荐指数
1
解决办法
1836
查看次数

标签 统计

memory ×1

python ×1

python-multiprocessing ×1