Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.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 X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.05; 'subject:How': 0.09; 'python': 0.09; 'received:141': 0.13; '(ubuntu': 0.16; 'escribi\xf3:': 0.16; 'subject:limit': 0.16; 'subject:usage': 0.16; 'processor': 0.17; 'typical': 0.17; 'solution.': 0.18; 'module': 0.19; 'all,': 0.21; 'import': 0.21; 'cc:2**0': 0.23; 'tools,': 0.23; 'external': 0.24; 'linux': 0.24; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'related': 0.30; 'to:addr:python-list': 0.33; 'sometimes': 0.35; 'there': 0.35; 'but': 0.36; 'useful': 0.36; 'possible': 0.37; 'does': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'think': 0.40; 'limit': 0.65; 'regards.': 0.66; 'lose': 0.71; 'saw': 0.75; 'few.': 0.93 From: DPalao To: python-list@python.org Subject: Re: How to limit CPU usage in Python Date: Tue, 25 Sep 2012 17:07:07 +0200 User-Agent: KMail/4.8.5 (Linux/3.2.12-gentoo; KDE/4.8.5; x86_64; ; ) In-Reply-To: <505B326C.1060503@cnic.edu.cu> References: <505B326C.1060503@cnic.edu.cu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348586033 news.xs4all.nl 6894 [2001:888:2000:d::a6]:58118 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30098 On Jueves septiembre 20 2012 11:12:44 Rolando Ca=F1er Roblejo escribi=F3= : > Hi all, >=20 > 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 usef= ul > 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 solutio= n. > I am working with Linux (Ubuntu 10.04). >=20 > 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 t= he=20 tasks you are doing. Hope it helps, Regards --=20 Miller's Slogan: =09Lose a few, lose a few.