Re: How to limit CPU usage in Python

Discussion in 'Python' started by DPalao, Sep 25, 2012.

  1. DPalao

    DPalao Guest

    On Jueves septiembre 20 2012 11:12:44 Rolando Cañer Roblejo escribió:
    > 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 moduleI
    > 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).
    >
    > Best regards.


    Hola,
    Sometimes a stupid solution like the following does the trick:

    > import time
    > for t in tasks:
    > do_something(t)
    > time.sleep(some_seconds)


    where "some_seconds" is a number related to the typical time-scale of the
    tasks you are doing.

    Hope it helps,

    Regards


    --
    Miller's Slogan:
    Lose a few, lose a few.
    DPalao, Sep 25, 2012
    #1
    1. Advertising

  2. DPalaoæ–¼ 2012å¹´9月25日星期二UTC+8下åˆ11時13分54秒寫é“:
    > On Jueves septiembre 20 2012 11:12:44 Rolando Cañer Roblejo escribió:
    >
    > > 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).

    >
    > >

    >
    > > Best regards.

    >
    >
    >
    > Hola,
    >
    > Sometimes a stupid solution like the following does the trick:
    >
    >
    >
    > > import time

    >
    > > for t in tasks:

    >
    > > do_something(t)

    >
    > > time.sleep(some_seconds)

    >
    >
    >
    > where "some_seconds" is a number related to the typical time-scale of the
    >
    > tasks you are doing.
    >
    >
    >
    > Hope it helps,
    >
    >
    >
    > Regards
    >
    >
    >
    >
    >
    > --
    >
    > Miller's Slogan:
    >
    > Lose a few, lose a few.


    I think I'll prefer to use a generator of my object in python
    to replace the sleep from the unix world. The reason is that I am not paid
    from selling or buying work-stations in some business unit directly and immediately.
    88888 Dihedral, Sep 25, 2012
    #2
    1. Advertising

  3. DPalaoæ–¼ 2012å¹´9月25日星期二UTC+8下åˆ11時13分54秒寫é“:
    > On Jueves septiembre 20 2012 11:12:44 Rolando Cañer Roblejo escribió:
    >
    > > 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).

    >
    > >

    >
    > > Best regards.

    >
    >
    >
    > Hola,
    >
    > Sometimes a stupid solution like the following does the trick:
    >
    >
    >
    > > import time

    >
    > > for t in tasks:

    >
    > > do_something(t)

    >
    > > time.sleep(some_seconds)

    >
    >
    >
    > where "some_seconds" is a number related to the typical time-scale of the
    >
    > tasks you are doing.
    >
    >
    >
    > Hope it helps,
    >
    >
    >
    > Regards
    >
    >
    >
    >
    >
    > --
    >
    > Miller's Slogan:
    >
    > Lose a few, lose a few.


    I think I'll prefer to use a generator of my object in python
    to replace the sleep from the unix world. The reason is that I am not paid
    from selling or buying work-stations in some business unit directly and immediately.
    88888 Dihedral, Sep 25, 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:
    172
    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:
    266
    Ramchandra Apte
    Sep 22, 2012
  5. Paul Rubin

    Re: How to limit CPU usage in Python

    Paul Rubin, Sep 23, 2012, in forum: Python
    Replies:
    2
    Views:
    335
    Jerry Hill
    Sep 27, 2012
Loading...

Share This Page