Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to force your computer to devote less CPU in exchange for more time when running a python program? [duplicate]

I'm running a python program that's a fairly intensive test of many possible scenarios using a big-O of n algorithm. It's just brute-forcing it by testing over a billion different possibilities using at least five nested loops.

Anyway, I'm not concerned with how much time the program takes. It's fine to run in the background for long periods of time, it's just that I can't have it clogging up the CPU. Is there any way in Python (3.3) to devote less CPU to a program in exchange for giving it more time?

Thanks in advance.

like image 692
Charles Clayton Avatar asked Dec 21 '25 15:12

Charles Clayton


1 Answers

A simpler solution might be to nice or re-nice your app. If you are running a Unix variant (Linux, *BSD, Mac), try something like this:

nice -n 19 python my_code.py

More info here: https://en.wikipedia.org/wiki/Nice_(Unix)

On Windows, you can try to set the priority via Task Manager (locate the Python process in Processes tab, right-click and select Set Priority).

like image 149
Johanns Gregorian Avatar answered Dec 24 '25 04:12

Johanns Gregorian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!