我在使用 python 多处理库时遇到了一个奇怪的问题.
I encountered a weird problem while using python multiprocessing library.
我的代码如下所示:我为每个符号、日期"元组生成一个进程.之后我结合结果.
My code is sketched below: I spawn a process for each "symbol, date" tuple. I combine the results afterwards.
我希望当一个进程完成对符号,日期"元组的计算时,它应该释放它的内存吗?显然情况并非如此.我看到几十个进程(尽管我将进程池的大小设置为 7)在机器中挂起¹.它们不消耗 CPU,也不释放内存.
I expect that when a process has done computing for a "symbol, date" tuple, it should release its memory? apparently that's not the case. I see dozens of processes (though I set the process pool to have size 7) that are suspended¹ in the machine. They consume no CPU, and they don't release the memory.
如何让进程在完成计算后释放其内存?
How do I let a process release its memory, after it has done its computation?
谢谢!
¹暂停"是指它们在 ps 命令中的状态显示为S+"
¹ by "suspended" I mean their status in ps command is shown as "S+"
def do_one_symbol( symbol, all_date_strings ):
pool = Pool(processes=7)
results = [];
for date in all_date_strings:
res = pool.apply_async(work, [symbol, date])
results.append(res);
gg = mm = ss = 0;
for res in results:
g, m, s = res.get()
gg += g;
mm += m;
ss += s;
您是否尝试使用 pool.close 然后等待进程完成 pool.join,因为如果父进程继续运行并且不等待子进程他们会变成僵尸
这篇关于Python多处理 - 进程完成后如何释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Python 多处理模块的 .join() 方法到底在做什么?What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多处理模块的 .join() 方法到底在做什么?)
在 Python 中将多个参数传递给 pool.map() 函数Passing multiple parameters to pool.map() function in Python(在 Python 中将多个参数传递给 pool.map() 函数)
multiprocessing.pool.MaybeEncodingError: 'TypeError("multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEnc
Python 多进程池.当其中一个工作进程确定不再需要Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多进程池.当其中一
如何将队列引用传递给 pool.map_async() 管理的函数How do you pass a Queue reference to a function managed by pool.map_async()?(如何将队列引用传递给 pool.map_async() 管理的函数?)
与多处理错误的另一个混淆,“模块"对象没yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(与多处理错误的另一个混淆,“模块对象