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


Groups > comp.lang.python > #29716

Re: How to limit CPU usage in Python

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <maniandram01@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'subject:How': 0.09; 'python': 0.09; 'compute': 0.09; 'terry': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; '(ubuntu': 0.16; 'limiting': 0.16; 'presume': 0.16; 'reedy': 0.16; 'simpson': 0.16; 'subject:limit': 0.16; 'subject:usage': 0.16; 'wrote:': 0.17; 'processor': 0.17; 'solution.': 0.18; 'module': 0.19; 'meant': 0.21; 'tools,': 0.23; 'cc:no real name:2**0': 0.24; 'external': 0.24; 'cc:2**1': 0.24; 'linux': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'cpu': 0.29; 'could': 0.32; '(with': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'useful': 0.36; 'possible': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'end': 0.40; 'think': 0.40; 'easy': 0.60; 'first': 0.61; 'limited.': 0.64; 'limit': 0.65; 'saw': 0.75; 'yourself,': 0.75; 'received:209.85.216.184': 0.84
Newsgroups comp.lang.python
Date Fri, 21 Sep 2012 20:05:39 -0700 (PDT)
In-Reply-To <mailman.1050.1348271054.27098.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=122.167.84.54; posting-account=uPFZNQoAAAAm9w7z13q1SjWNKNjztdcD
References <k3fhmq$be4$2@ger.gmane.org> <mailman.1050.1348271054.27098.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 122.167.84.54
MIME-Version 1.0
Subject Re: How to limit CPU usage in Python
From Ramchandra Apte <maniandram01@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org, Terry Reedy <tjreedy@udel.edu>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.1058.1348283142.27098.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348283142 news.xs4all.nl 6887 [2001:888:2000:d::a6]:46135
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29716

Show key headers only | View raw


you

On Saturday, 22 September 2012 05:14:15 UTC+5:30, Cameron Simpson  wrote:
> On 20Sep2012 12:53, Terry Reedy <tjreedy@udel.edu> wrote:
> 
> | On 9/20/2012 12:46 PM, Terry Reedy wrote:
> 
> | > On 9/20/2012 11:12 AM, Rolando CaƱer Roblejo wrote:
> 
> | >> 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).
> 
> | >
> 
> | > Call the external tools with subprocess.open.
> 
> | 
> 
> | I meant to end that with ? as I don't know how easy it is to get the 
> 
> | external id of the calling process that is to be limited. I presume that 
> 
> | can be done by first calling ps (with subprocess) and searching the 
> 
> | piped-back output.
> 
> 
> 
> If you're limiting yourself, os.getpid().
> 
> -- 
> 
> Cameron Simpson <cs@zip.com.au>

You could use os.times to compute the CPU usage and then stop the process when that happens and then start it after some time using signals.

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


Thread

Re: How to limit CPU usage in Python Cameron Simpson <cs@zip.com.au> - 2012-09-22 09:44 +1000
  Re: How to limit CPU usage in Python Ramchandra Apte <maniandram01@gmail.com> - 2012-09-21 20:05 -0700
  Re: How to limit CPU usage in Python Ramchandra Apte <maniandram01@gmail.com> - 2012-09-21 20:05 -0700

csiph-web