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!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.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'subject:Python': 0.05; 'subject:How': 0.09; 'python': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; '(ubuntu': 0.16; 'escribi\xc3\xb3:': 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; 'cc:no real name:2**0': 0.24; 'external': 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; 'replace': 0.27; 'sleep': 0.29; 'related': 0.30; 'received:google.com': 0.34; 'from:addr:googlemail.com': 0.35; 'received:209.85.220': 0.35; 'sometimes': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'useful': 0.36; "i'll": 0.36; 'possible': 0.37; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'unit': 0.38; 'object': 0.38; 'some': 0.38; 'where': 0.40; 'skip:" 10': 0.40; 'think': 0.40; 'selling': 0.64; 'limit': 0.65; 'regards.': 0.66; 'buying': 0.69; 'business': 0.70; 'lose': 0.71; 'saw': 0.75; '8bit%:70': 0.91; 'received:209.85.220.184': 0.91; 'few.': 0.93 Newsgroups: comp.lang.python Date: Tue, 25 Sep 2012 15:39:39 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.192.32.215; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw References: <505B326C.1060503@cnic.edu.cu> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 123.192.32.215 MIME-Version: 1.0 Subject: Re: How to limit CPU usage in Python From: 88888 Dihedral To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: , Message-ID: Lines: 75 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348612782 news.xs4all.nl 6920 [2001:888:2000:d::a6]:55972 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30132 DPalao=E6=96=BC 2012=E5=B9=B49=E6=9C=8825=E6=97=A5=E6=98=9F=E6=9C=9F=E4=BA= =8CUTC+8=E4=B8=8B=E5=8D=8811=E6=99=8213=E5=88=8654=E7=A7=92=E5=AF=AB=E9=81= =93=EF=BC=9A > On Jueves septiembre 20 2012 11:12:44 Rolando Ca=C3=B1er Roblejo escribi= =C3=B3: >=20 > > Hi all, >=20 > >=20 >=20 > > Is it possible for me to put a limit in the amount of processor usage (= % >=20 > > CPU) that my current python script is using? Is there any module useful >=20 > > for this task? I saw Resource module but I think it is not the module I >=20 > > am looking for. Some people recommend to use nice and cpulimit unix >=20 > > tools, but those are external to python and I prefer a python solution. >=20 > > I am working with Linux (Ubuntu 10.04). >=20 > >=20 >=20 > > Best regards. >=20 >=20 >=20 > Hola, >=20 > Sometimes a stupid solution like the following does the trick: >=20 >=20 >=20 > > import time >=20 > > for t in tasks: >=20 > > do_something(t) >=20 > > time.sleep(some_seconds) >=20 >=20 >=20 > where "some_seconds" is a number related to the typical time-scale of the= =20 >=20 > tasks you are doing. >=20 >=20 >=20 > Hope it helps, >=20 >=20 >=20 > Regards >=20 >=20 >=20 >=20 >=20 > --=20 >=20 > Miller's Slogan: >=20 > 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= =20 from selling or buying work-stations in some business unit directly and im= mediately.