Re: How to limit CPU usage in Python

Discussion in 'Python' started by Paul Rubin, Sep 23, 2012.

  1. Paul Rubin

    Paul Rubin Guest

    Rolando Cañer Roblejo <> 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.
    Paul Rubin, Sep 23, 2012
    #1
    1. Advertising

  2. Paul Rubin

    Dwight Hutto Guest

    rites:
    >> 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.
    >


    The script in constant runtime, unless it's in relation to other
    processes, could be put on a % based sleep constant variable.

    If the script is constantly running the same processes, and the OP
    wants to limit it statistically, then at a critical portion in the
    script sleep for a constant, or maybe, dynamic variable.

    The only other is to create an app, disassemble it, and then refine
    the asm instructions being used at the assembly level, but I'm just
    scratching the surface of those enhancements.



    --
    Best Regards,
    David Hutto
    CEO: http://www.hitwebdevelopment.com
    Dwight Hutto, Sep 23, 2012
    #2
    1. Advertising

  3. Paul Rubin

    Jerry Hill Guest

    On Thu, Sep 27, 2012 at 12:58 PM, Prasad, Ramit
    <> wrote:
    > 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.


    On windows, you can also set the priority of a process, though it's a
    little different from the *nix niceness level. See
    http://code.activestate.com/recipes/496767/ for a recipe using
    pywin32. I believe the psutil module handles this too, but I don't
    think it manages to abstract away the platform differences.

    --
    Jerry
    Jerry Hill, Sep 27, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Terry Reedy

    Re: How to limit CPU usage in Python

    Terry Reedy, Sep 20, 2012, in forum: Python
    Replies:
    0
    Views:
    155
    Terry Reedy
    Sep 20, 2012
  2. Terry Reedy

    Re: How to limit CPU usage in Python

    Terry Reedy, Sep 20, 2012, in forum: Python
    Replies:
    0
    Views:
    154
    Terry Reedy
    Sep 20, 2012
  3. Jerry Hill

    Re: How to limit CPU usage in Python

    Jerry Hill, Sep 20, 2012, in forum: Python
    Replies:
    0
    Views:
    170
    Jerry Hill
    Sep 20, 2012
  4. Cameron Simpson

    Re: How to limit CPU usage in Python

    Cameron Simpson, Sep 22, 2012, in forum: Python
    Replies:
    2
    Views:
    264
    Ramchandra Apte
    Sep 22, 2012
  5. Dwight Hutto

    Re: How to limit CPU usage in Python

    Dwight Hutto, Sep 23, 2012, in forum: Python
    Replies:
    0
    Views:
    182
    Dwight Hutto
    Sep 23, 2012
Loading...

Share This Page