Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lowering process priority of multiprocessing.Pool on Windows

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

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?

like image 337
JasonEdinburgh Avatar asked Apr 14 '14 12:04

JasonEdinburgh


People also ask

How do I reduce process priority?

You can change the scheduling priority of a running process to a value lower or higher than the base scheduling priority by using the renice command from the command line. This command changes the nice value of a process.

What is process Priority in Windows?

Process priority is simply the 'importance' of each process. Tasks that are essential for the smooth running of your computer (mostly system processes) are accorded a higher priority than an application running on top. This ensures that even under the maximum load, the core capabilities of your PC are not affected.

How do you stop a multiprocessing process?

A process can be killed by calling the Process. terminate() function. The call will only terminate the target process, not child processes. The method is called on the multiprocessing.


1 Answers

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)
like image 168
Giampaolo Rodolà Avatar answered Nov 02 '22 09:11

Giampaolo Rodolà