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


Groups > comp.lang.python > #30308

RE: How to limit CPU usage in Python

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'completeness': 0.07; 'subject:How': 0.09; 'python': 0.09; 'received:155': 0.09; 'assume': 0.11; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:155.180.234': 0.16; 'received:155.180.234.122': 0.16; 'received:159.53': 0.16; 'received:159.53.110': 0.16; 'received:169.70': 0.16; 'received:169.70.184': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:se3.svr.bankone.net': 0.16; 'received:svr.bankone.net': 0.16; 'resource,': 0.16; 'resource.': 0.16; 'securities,': 0.16; 'subject:limit': 0.16; 'subject:usage': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; 'processor': 0.17; 'tim': 0.18; 'module': 0.19; 'appropriate': 0.20; 'to:name:python- list@python.org': 0.20; 'fairly': 0.21; 'context.': 0.22; 'received:169.254': 0.24; 'paul': 0.24; 'host': 0.24; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'checking': 0.27; 'accuracy': 0.27; 'cpu': 0.29; 'sleep': 0.29; 'writes:': 0.29; 'received:169': 0.29; 'affects': 0.33; 'handle': 0.33; 'problem': 0.33; 'to:addr :python-list': 0.33; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'compare': 0.36; 'header:Received:9': 0.36; 'useful': 0.36; 'should': 0.36; 'possible': 0.37; 'does': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'where': 0.40; 'your': 0.60; 'high': 0.61; 'time,': 0.62; 'information,': 0.63; 'url:email': 0.63; 'limit': 0.65; 'legal': 0.65; 'want,': 0.65; 'subject': 0.66; 'purchase': 0.67; 'power': 0.74; '100%': 0.76; 'sale': 0.76; 'excessive': 0.84; 'received:169.254.8': 0.84; 'thermal': 0.84; 'unaware': 0.84
X-DKIM OpenDKIM Filter v2.1.3 sj1.jpmchase.com q8RGwxZR027515
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1348765140; bh=oMe6R7rc3xppAu66SZlE8W4xghjamlpu9IW4fz0h6Ms=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=P+45zGD9Ab7j3NzXc1FmEX4yJXevW6Nnt+0hqfc4gLXON2LRQ8iGJBQwTxhNztKtS PzeJQMQogTnAQ4jLomyXN7DvuvEQEcfn6SNqt1HkPFauDGdoUgQadoyf9BAJxoptIL In6t3+0K1+n78pAAfupEfL3UyiawdPaupL5wgARI=
X-DKIM OpenDKIM Filter v2.1.3 sz1.jpmchase.com q8RGwxkR007588
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1348765139; bh=oMe6R7rc3xppAu66SZlE8W4xghjamlpu9IW4fz0h6Ms=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=r7nCGQib5RBNEYacubChjYptCc2JgX1rJKAaysdIJ5dyFXjBoJwlsJxZqrUgUUG5d dJIw0+T4U2l/fW6VIEnaUfIcmamP0+iIRubm6rUUn7Az6oIFw5D647O/aMN/nMsRop pRGV6wUaJqXNlSLWVoS+ZP8i375e3Im5UZC9ni+o=
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: How to limit CPU usage in Python
Thread-Topic How to limit CPU usage in Python
Thread-Index AQHNmRbO0dNAWZRQyE+Qo8TZwmr09peebi1A
Date Thu, 27 Sep 2012 16:58:45 +0000
References <mailman.960.1348154419.27098.python-list@python.org> <7xpq5d7j5e.fsf@ruckus.brouhaha.com>
In-Reply-To <7xpq5d7j5e.fsf@ruckus.brouhaha.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.47]
Content-Transfer-Encoding base64
MIME-Version 1.0
X-DLP-FWD Yes
Content-Type text/plain; charset="utf-8"
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>
Newsgroups comp.lang.python
Message-ID <mailman.1498.1348765149.27098.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348765150 news.xs4all.nl 6884 [2001:888:2000:d::a6]:33874
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30308

Show key headers only | View raw


Paul Rubin wrote:
> Rolando Cañer Roblejo <rolando.caner@cnic.edu.cu> 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.

The problem is that checking the CPU usage is fairly misleading 
if you are worried about contention. If your process takes up 
100% of CPU and nothing else needs the resource, does it matter? 
I would not want to sleep *unless* something else needs the 
resource. Of course, there might be a good/easy way of checking
usage + contention, but I am unaware of any off the top of my
head.

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.



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

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


Thread

How to limit CPU usage in Python Rolando Cañer Roblejo <rolando.caner@cnic.edu.cu> - 2012-09-20 11:12 -0400
  Re: How to limit CPU usage in Python Tim Roberts <timr@probo.com> - 2012-09-22 13:55 -0700
    Re: How to limit CPU usage in Python Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-22 23:24 -0400
  Re: How to limit CPU usage in Python Paul Rubin <no.email@nospam.invalid> - 2012-09-22 16:05 -0700
    Re: How to limit CPU usage in Python Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-22 23:04 -0400
    Re: How to limit CPU usage in Python Tim Roberts <timr@probo.com> - 2012-09-24 21:09 -0700
    RE: How to limit CPU usage in Python "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-09-27 16:58 +0000
    Re: How to limit CPU usage in Python Jerry Hill <malaclypse2@gmail.com> - 2012-09-27 13:07 -0400

csiph-web