Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30308

RE: How to limit CPU usage in Python

From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Subject RE: How to limit CPU usage in Python
Date 2012-09-27 16:58 +0000
References <mailman.960.1348154419.27098.python-list@python.org> <7xpq5d7j5e.fsf@ruckus.brouhaha.com>
Newsgroups comp.lang.python
Message-ID <mailman.1498.1348765149.27098.python-list@python.org> (permalink)

Show all headers | View raw


Paul Rubin wrote:
> Rolando Cañer Roblejo <rolando.caner@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.

The problem is that checking the CPU usage is fairly misleading 
if you are worried about contention. If your process takes up 
100% of CPU and nothing else needs the resource, does it matter? 
I would not want to sleep *unless* something else needs the 
resource. Of course, there might be a good/easy way of checking
usage + contention, but I am unaware of any off the top of my
head.

On *nix you should just set the appropriate nice-ness and then 
let the OS handle CPU scheduling. Not sure what you would do 
for Windows--I assume OS X is the same as *nix for this context.



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to limit CPU usage in Python Rolando Cañer Roblejo <rolando.caner@cnic.edu.cu> - 2012-09-20 11:12 -0400
  Re: How to limit CPU usage in Python Tim Roberts <timr@probo.com> - 2012-09-22 13:55 -0700
    Re: How to limit CPU usage in Python Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-22 23:24 -0400
  Re: How to limit CPU usage in Python Paul Rubin <no.email@nospam.invalid> - 2012-09-22 16:05 -0700
    Re: How to limit CPU usage in Python Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-22 23:04 -0400
    Re: How to limit CPU usage in Python Tim Roberts <timr@probo.com> - 2012-09-24 21:09 -0700
    RE: How to limit CPU usage in Python "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-09-27 16:58 +0000
    Re: How to limit CPU usage in Python Jerry Hill <malaclypse2@gmail.com> - 2012-09-27 13:07 -0400

csiph-web