Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901; t=1348169327; bh=RKSwYkUVmCIlCBoiWrhYu1qoeXT+K7YrwhFjbA3Bpcs=; h=To:From:Subject:Date:Message-ID:References:Mime-Version: Content-Type:Content-Transfer-Encoding:In-Reply-To; b=oFdyb0vvtDOEwOmqE0o2ozI560F/OCUeOlQoHbSPvT5G+VT5ClyN84fjnzq27bpzG vGKuvTiuNJ7R+8mA8LuF/tXEq/UGmTyuPMzVzlC/+ADDDdSXbMrabpP4Ou28PcbnjN CCMZfiqBP6LYJXX9PWA63LerThHd7LYiW0r5NRXk= X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'api.': 0.04; 'subject:Python': 0.05; 'wrapper': 0.07; 'subject:How': 0.09; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wraps': 0.09; '(ubuntu': 0.16; 'altered': 0.16; 'from:name:christian heimes': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:limit': 0.16; 'subject:usage': 0.16; 'url:linux': 0.16; 'from:addr:python.org': 0.17; 'processor': 0.17; 'solution.': 0.18; 'module': 0.19; 'all,': 0.21; 'tools,': 0.23; 'external': 0.24; 'feature': 0.24; 'linux': 0.24; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'options': 0.27; 'header:X -Complaints-To:1': 0.28; 'cpu': 0.29; 'priority': 0.29; 'priority.': 0.29; 'url:code': 0.29; 'seconds': 0.30; 'to:addr :python-list': 0.33; 'christian': 0.34; 'described': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'useful': 0.36; 'possible': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'hello,': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'url:p': 0.63; 'limit': 0.65; 'total': 0.65; 'saw': 0.75; 'nice,': 0.84; 'scheduling': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Christian Heimes Subject: Re: How to limit CPU usage in Python Date: Thu, 20 Sep 2012 21:28:34 +0200 References: <505B326C.1060503@cnic.edu.cu> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: g228162000.adsl.alicedsl.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 In-Reply-To: <505B326C.1060503@cnic.edu.cu> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348169328 news.xs4all.nl 6958 [2001:888:2000:d::a6]:37753 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29570 Am 20.09.2012 17:12, schrieb Rolando Caņer Roblejo: > 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). Hello, you have two options here. You can either limit the total amount of CPU seconds with the resource module or reduce the priority and scheduling priority of the process. The resource module is a wrapper around the setrlimit and getrlimit feature as described in http://linux.die.net/man/2/setrlimit . The scheduling priority can be altered with nice, get/setpriority or io priority. The psutil package http://code.google.com/p/psutil/ wraps all functions in a nice Python API. Regards Christian