本文介绍了降低多处理的进程优先级.Windows上的池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用multiprocessing.Pool()并行处理一些繁重的Pandas处理,但发现它有点太成功了.我的CPU使用率达到100%,我的整个计算机变得非常无响应.甚至鼠标也变得难以使用.

I use multiprocessing.Pool() to parallelize some heavy Pandas processing but find that it is a bit too successful. My CPU usage goes to 100% and my entire computer becomes very unresponsive. Even the mouse becomes difficult to use.

我可以使用此代码更改流程的流程优先级.

I can change the process priority of my process with this code.

import psutil
p = psutil.Process(os.getpid())
p.nice = psutil.BELOW_NORMAL_PRIORITY_CLASS

但是,当我在Windows任务管理器中查看时,我发现只有主python.exe进程已更改为低于正常优先级.

However, when I look in Windows Task Manager I find that only the main python.exe process has been changed to below normal priority.

是否有一种降低池进程优先级的好方法?

Is there a good way to reduce the priority of the pool processes?

推荐答案

您可以在生成进程的子级后尝试设置它们的优先级.像这样:

You can try setting priority of your process' children after you spawned them. Something like:

import psutil

# spawn children and/or launch process pool here

parent = psutil.Process()
parent.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS)
for child in parent.children():
    child.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS)

这篇关于降低多处理的进程优先级.Windows上的池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 06:20