control CPU usage
Jiang Fung Wong
kakarukeys at gmail.com
Sun Sep 20 05:21:14 CEST 2009
Thank you for the information. I think I've some idea what the problem is
about after seeing the replies.
More information about my system and my script
PIII 1Ghz, 512MB RAM, Windows XP SP3
The script monitors global input using PyHook,
and calculates on the information collected from the events to output some
numbers. Based on the numbers, the script then performs some automation
using SendKeys module.
here is the memory usage:
firefox.exe, 69MB, 109MB
svchost.exe, 26MB, 17MB
pythonw.exe, 22MB, 17MB
searchindexer.exe, 16MB, 19MB
My first guess is that the script calculated for too long time after
receiving an event before propagating it to the default handler, resulting
the system to be non-responsive. I will try to implement the calculation
part in another thread.
Then the separate will have 100% CPU usage, hope the task scheduling of
Windows works in my favour.
On Sun, Sep 20, 2009 at 5:22 AM, Dave Angel <davea at ieee.org> wrote:
> kakarukeys wrote:
>> When I am running a loop for a long time, calculating heavily, the CPU
>> is at 100%, making the comp not so responsive. Is there a way to
>> control the
>> CPU usage at say 80%? putting a time.sleep(0.x) doesn't seem to help
>> although CPU usage level is reduced, but it's unstable.
> Controlling a task's scheduling is most definitely OS-dependent., so you
> need to say what OS you're running on. And whether it's a multi-core and or
> duo processor.
> In Windows, there is a generic way to tell the system that you want to give
> a boost to whatever task has the user focus (generally the top-window on the
> desktop). On some versions, that's the default, on others, it's not. You
> change it from Control Panel. I'd have to go look to tell you what applet,
> but I don't even know if you're on Windows.
> In addition, a program can adjust its own priority, much the way the Unix
> 'nice' command works. You'd use the Win32 library for that.
> And as you already tried, you can add sleep() operations to your
> But if you're looking at the task list in the Windows Task Manager, you
> aren't necessarily going to see what you apparently want. There's no way to
> programmatically tell the system to use a certain percentage for a given
> task. If there's nothing else to do, then a low priority task is still
> going to get nearly 100% of the CPU. Good thing. But even if there are
> other things to do, the scheduling is a complex interaction between what
> kinds of work the various processes have been doing lately, how much memory
> load they have, and what priority they're assigned.
> If you just want other processes to be "responsive" when they've got the
> focus, you may want to make that global setting. But you may need to better
> define "responsive" and "unstable."
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list