Fwd: Running a python program during idle time only

James Carroll mrmaple at gmail.com
Mon May 23 14:20:01 EDT 2005


I think you can keep your sleep commands in your program to keep it
from hogging the cpu even when you are running it as nice.

You know, even more important than cpu load (since your indexer is
accessing the hard drive, is hard drive access..)  You can monitor the
bytes  / second going to the hard drives using a WMI query similar to
the one that gives you LoadPercentage for a cpu.

If something Is trying to read and write to the hard drive, and your
indexer is going at the same time, hard drive head contention can slow
down both processess to a crawl.  (Say your program is in C:/apps  and
another program is simutaneously trying to read from C:/data... the
heads have to seek back and forth between the two spots on the hard
drive, and it's much faster to do all the C:/apps accesses and then
later do all the C:/data accesses.)

So I think my approach would be to have the indexer take about 10% of
cpu load while it is active, and as soon as another process is doing
enough reading / writing to the hard drive, stop and wait for about
five minutes... then continuing.

The screen saver idea is another good one.  I found this the other day...
  http://homepage.hispeed.ch/py430/python/win32screensaver-0.3.2.zip

The problem is that any potential user that really likes their pretty
screen saver (Helios under Ubuntu... droool............ slurp.)  then
they can't have both your indexer and their pretty screensaver active
during idle time.

-Jim







On 23 May 2005 10:32:18 -0700, los <carlos80 at gmail.com> wrote:
> Thanks for all the replies.
>
> I did try using nice under windows.  I created a java program that
> would just loop and print numbers on the screen.  Even when I ran that
> simple program with nice, (lets call it program A) as soon as I started
> the program the cpu went all the way to 100% usage.  Then when I ran
> another program that did the same thing (lets call it program B),
> program A halted to let B finish, then it started again.  Nevertheless
> it still hogged all the cpu while I was using the computer.
>
> For my indexing program I just wrote a simple python program and called
> on the python os.walk() method to iterate through the drive and then it
> connects to a database to store some information.  Then I wrote a
> simple interface to connect to the database to search for files using
> visual basic.  Once everything is indexed it works fine, but it would
> be nice to have the program looping through and indexing the files all
> the time to account to file updates, deletes, and relocation, but
> without hurting the performance when I'm using the computer.
>
> So really what I am looking for is some way to have the program only
> start indexing and crawling through the hd after 5 minutes of no user
> interaction with the computer.
>
> I'm going to take a look at this CPU load possibility.  But I'm afraid
> that this will work similarly to "nice" in which case it will let the
> program kick in when the CPU isn't being used heavily, but I might
> still be using the computer.
>
> thanks once again!
>
> -los
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>



More information about the Python-list mailing list