Dear All,<br><br>Thank you for the information. I think I've some idea what the problem is about after seeing the replies.<br><br>More information about my system and my script<br><br>PIII 1Ghz, 512MB RAM, Windows XP SP3<br>
<br>The script monitors global input using PyHook,<br>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.<br>
<br>here is the memory usage:<br>firefox.exe, 69MB, 109MB<br>svchost.exe, 26MB, 17MB<br>pythonw.exe, 22MB, 17MB<br>searchindexer.exe, 16MB, 19MB<br><br>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.<br>
Then the separate will have 100% CPU usage, hope the task scheduling of Windows works in my favour.<br><br><div class="gmail_quote">On Sun, Sep 20, 2009 at 5:22 AM, Dave Angel <span dir="ltr"><<a href="mailto:davea@ieee.org">davea@ieee.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">kakarukeys wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
When I am running a loop for a long time, calculating heavily, the CPU<br>
usage<br>
is at 100%, making the comp not so responsive. Is there a way to<br>
control the<br>
CPU usage at say 80%? putting a time.sleep(0.x) doesn't seem to help<br>
although CPU usage level is reduced, but it's unstable.<br>
<br>
Regards,<br>
W.J.F.<br>
<br>
  <br>
</blockquote></div>
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.<br>
<br>
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.<br>

<br>
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.<br>
<br>
And as you already tried, you can add sleep() operations to your application.<br>
<br>
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.<br>

<br>
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."<br>

<br>
DaveA<br>
</blockquote></div><br>