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 X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.05; 'level,': 0.07; 'subject:How': 0.09; 'python': 0.09; 'app,': 0.09; 'received:mail-vb0-f46.google.com': 0.09; 'portion': 0.13; 'asm': 0.16; 'subject:limit': 0.16; 'subject:usage': 0.16; 'variable.': 0.16; 'processor': 0.17; 'received:209.85.212.46': 0.18; 'module': 0.19; 'constant': 0.22; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'cpu': 0.29; 'sleep': 0.29; "i'm": 0.29; 'running': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'compare': 0.36; 'useful': 0.36; 'possible': 0.37; 'being': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'time,': 0.62; 'limit': 0.65; 'want,': 0.65; 'maybe,': 0.84; 'surface': 0.84; 'processes,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=5kVHdA8bDbsTXy1Y8OaotaP/IL1ijxDq5M5kdoL1cRw=; b=XseIlscXRMSJ/Aqw/sfBiO2AaB4HsdyEu9CwMtFMAsd6tvd/xzM+OEzsIcZqDDKyQN PTIUIkFsZRKLhW/WAzKDMfj9UgE9h3MUT67Bd0GwW1m9KVW3JyJAp4TmLY01od91Qnkr vCKVaQHm+xRQDoCrpPGGa6rXHXPM2fzUhvoZ2FoWmte9yoYMG/Dr44eSKI0+rmiDHD2n blZyRndNe+cETFV56MPMdJopxLMq+PqCyupJZwJREApqjqqz9YD4kdj+iKKTxZZpoC0L Z6dQpSJstiLmkP+gsRS4lFSYLe4Rk8vgHtzy3i46dw1i4IYS8VcaFnxGLLWlmG9T5gp4 zNLQ== MIME-Version: 1.0 In-Reply-To: <7xpq5d7j5e.fsf@ruckus.brouhaha.com> References: <7xpq5d7j5e.fsf@ruckus.brouhaha.com> Date: Sat, 22 Sep 2012 23:04:39 -0400 Subject: Re: How to limit CPU usage in Python From: Dwight Hutto To: python-list@python.org 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348369482 news.xs4all.nl 6886 [2001:888:2000:d::a6]:36118 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29777 rites: >> 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. > The script in constant runtime, unless it's in relation to other processes, could be put on a % based sleep constant variable. If the script is constantly running the same processes, and the OP wants to limit it statistically, then at a critical portion in the script sleep for a constant, or maybe, dynamic variable. The only other is to create an app, disassemble it, and then refine the asm instructions being used at the assembly level, but I'm just scratching the surface of those enhancements. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com