How to limit CPU usage in Python

Paul Rubin no.email at nospam.invalid
Sat Sep 22 19:05:49 EDT 2012


Rolando Cañer Roblejo <rolando.caner at cnic.edu.cu> writes:
> Is it possible for me to put a limit in the amount of processor usage
> (% CPU) that my current python script is using? Is there any module
> useful for this task? 

One way is check your cpu usage once in a while, compare with elapsed
time, and if your % usage is above what you want, sleep for a suitable
interval before proceeding.

Tim Roberts: reasons to want to do this might involve a shared host
where excessive cpu usage affects other users; or a computer with
limited power consumption, where prolonged high cpu activity causes
thermal or other problems.



More information about the Python-list mailing list