相关疑难解决方法(0)

使用Python多处理的高内存使用率

我已经看过几篇关于使用Python Multiprocessing模块的内存使用情况的帖子.然而问题似乎没有回答我在这里遇到的问题.我发布我的分析,希望有人可以帮助我.

问题

我正在使用多处理来并行执行任务,我注意到工作进程的内存消耗无限增长.我有一个小的独立示例,应该复制我注意到的.

import multiprocessing as mp
import time

def calculate(num):
    l = [num*num for num in range(num)]
    s = sum(l)
    del l       # delete lists as an  option
    return s

if __name__ == "__main__":
    pool = mp.Pool(processes=2)
    time.sleep(5)
    print "launching calculation"
    num_tasks = 1000
    tasks =  [pool.apply_async(calculate,(i,)) for i in range(num_tasks)]
    for f in tasks:    
        print f.get(5)
    print "calculation finished"
    time.sleep(10)
    print "closing  pool"
    pool.close()
    print "closed pool"
    print "joining pool"
    pool.join()
    print "joined pool"
    time.sleep(5)
Run Code Online (Sandbox Code Playgroud)

系统

我正在运行Windows,我使用任务管理器来监视内存使用情况.我正在运行Python …

python memory performance multiprocessing

37
推荐指数
1
解决办法
2万
查看次数

控制台窗口的输出是否有限制?

代码:
该程序检查输入的2个数字是否可以被数字2 - 9整除,并显示剩余的可分数(不包括被查看的数字).

static void Main(string[] args)
{
    for (int i = 2; i < 10; i++)
    {
        Challenge(2, 6, i);
    }
    Console.ReadLine();
}

static void Challenge(int num1, int num2, int Divisor)
{
    int sum = num1 + num2;
    bool SumDivisible = sum % Divisor == 0;
    bool num1Divisible = num1 % Divisor == 0;
    bool num2Divisible = num2 % Divisor == 0;

    int highNum = 80;
    List<int> NumbersDivisible = Enumerable.Range(1, highNum).Where(x => x % Divisor == 0).ToList();

    // …
Run Code Online (Sandbox Code Playgroud)

c# windows-console

3
推荐指数
2
解决办法
4132
查看次数