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


Groups > comp.lang.python > #29570 > unrolled thread

Re: How to limit CPU usage in Python

Started byChristian Heimes <christian@python.org>
First post2012-09-20 21:28 +0200
Last post2012-09-20 21:28 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to limit CPU usage in Python Christian Heimes <christian@python.org> - 2012-09-20 21:28 +0200

#29570 — Re: How to limit CPU usage in Python

FromChristian Heimes <christian@python.org>
Date2012-09-20 21:28 +0200
SubjectRe: How to limit CPU usage in Python
Message-ID<mailman.970.1348169328.27098.python-list@python.org>
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


[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web