Hakim
Hakim

Reputation: 3437

Limit CPU usage for a script

Is it possible for a Python script to limit the CPU power allocated to it?

Right now, I have a script (using only one core) that is using 100% of one CPU's core. I need it to use less than that amount.

Is there an equivalent to PHP's memory_limit in Python? or is there a library to manage memory allocation? (using sleep isn't a very elegant solution)

Upvotes: 7

Views: 11807

Answers (1)

gameboy1024
gameboy1024

Reputation: 76

Maybe try Python's resource package?

The resource package is basically a wraparound of setrlimit in UNIX. So you can set constrains for CPU/Memory usage, etc.

More about setrlimit in Linux

Upvotes: 6

Related Questions