Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to limit CPU usage in Python

Reply
Thread Tools

Re: How to limit CPU usage in Python

 
 
Jerry Hill
Guest
Posts: n/a
 
      09-20-2012
On Thu, Sep 20, 2012 at 11:12 AM, Rolando Cañer Roblejo
<(E-Mail Removed)> wrote:
> Hi all,
>
> 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? I saw Resource module but I think it is not the module I am
> looking for. Some people recommend to use nice and cpulimit unix tools, but
> those are external to python and I prefer a python solution. I am working
> with Linux (Ubuntu 10.04).


Maximum percentage of CPU used isn't normally something you control.
The only way I know of to do it involves having another process
monitor the thing you want to control and sending signals to stop and
start it (e.g., http://cpulimit.sourceforge.net/).

Typically, you instead want to control the priority (so that higher
priority apps can easily take more CPU time). That's what nice is for
(http://docs.python.org/library/os.html#os.nice). If you want to
limit a process in the same way that ulimit does, then the resources
module is what you want
(http://docs.python.org/library/resou...urce.setrlimit).

Is there a particular reason that you'd rather have your CPU sitting
idle, rather than continuing with whatever code is waiting to be run?
I'm having a hard time understanding what problem you might be having
that some combination of setting the nice level and imposing resource
limits won't handle.

--
Jerry
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: How to limit CPU usage in Python Paul Rubin Python 2 09-27-2012 05:07 PM
Re: How to limit CPU usage in Python Cameron Simpson Python 2 09-22-2012 03:05 AM
Re: How to limit CPU usage in Python Terry Reedy Python 0 09-20-2012 04:53 PM
Re: How to limit CPU usage in Python Terry Reedy Python 0 09-20-2012 04:46 PM



Advertisments