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

 
 
DPalao
Guest
Posts: n/a
 
      09-25-2012
On Jueves septiembre 20 2012 11:12:44 Rolando Caer 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.

 
Reply With Quote
 
 
 
 
88888 Dihedral
Guest
Posts: n/a
 
      09-25-2012
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.


 
Reply With Quote
 
 
 
 
88888 Dihedral
Guest
Posts: n/a
 
      09-25-2012
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.


 
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 Cameron Simpson Python 2 09-22-2012 03:05 AM
Re: How to limit CPU usage in Python Jerry Hill Python 0 09-20-2012 05:08 PM
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