Hi,
I'm trying to create a program similar to that of Google's desktop that
will crawl through the hard drive and index files. I have written the
program and as of now I just put the thread to sleep for 1 second after
indexing a couple of files.
I'm wondering if anyone knows of a way that I could make so that the
program will run at full speed only runs after the computer has been
idle for a while. I've looked at the "nice" command but that's not
exactly what I want.
Let me know if it isn't clear what I explained above.
Thanks 17 4006
"los" <ca******@gmail .com> writes: I'm trying to create a program similar to that of Google's desktop that will crawl through the hard drive and index files. I have written the program and as of now I just put the thread to sleep for 1 second after indexing a couple of files.
I'm wondering if anyone knows of a way that I could make so that the program will run at full speed only runs after the computer has been idle for a while. I've looked at the "nice" command but that's not exactly what I want.
On Unix, nice is exactly the answer. It's a lot more fine-grained than
what you're talking about, though. But it's the way things like
setiathome manage to run continuously without interfering with normal
usage.
If that's to fine grained for you, you could try waking up every few
minutes and checking the load average (via os.getloadavg), and only
doing work if the load average is low - say less than .5. While
running, you check the load average every couple of minutes and stop
if it rises noticably above 1 (you). The problem with this approach is
that it doesn't deal well with multiple tools doing this. I.e. - if
you run setiathome, your load average will always be above 1, so you
have to adjust your check value to take into account anything else
that might be in the background. Nice handles this automatically.
<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Quoth Mike Meyer <mw*@mired.org> :
| "los" <ca******@gmail .com> writes:
| > I'm trying to create a program similar to that of Google's desktop that
| > will crawl through the hard drive and index files. I have written the
| > program and as of now I just put the thread to sleep for 1 second after
| > indexing a couple of files.
| >
| > I'm wondering if anyone knows of a way that I could make so that the
| > program will run at full speed only runs after the computer has been
| > idle for a while. I've looked at the "nice" command but that's not
| > exactly what I want.
|
| On Unix, nice is exactly the answer. It's a lot more fine-grained than
| what you're talking about, though. But it's the way things like
| setiathome manage to run continuously without interfering with normal
| usage.
Well, he could certainly try it if he hasn't already, but I wouldn't
be too surprised if it really isn't exactly what he wants. Maybe it
depends on the scheduler, and maybe things have gotten a lot better
in that department, but from my experience a process can be niced pretty
hard and still tie up a lot of resources. A disk crawler sounds like
a good example.
I don't have any brilliant ideas, though. Your suggestion to use
os.getloadavg sounds good to me. It might be kind of neat if there
were some kind of APM ioctl that would register the calling process
for notification of pending disk spin down, low power mode etc.
Donn
There's probably a way to tell how long the user has been idle, but here's
how you can check the CPU load to see if it's elevated... (of course
your program might elevate it too.)
On linux, you can read from /proc/loadavg
Here's a fun thing to try on windows...
make sure you have the win32all package installed...
import win32com.client
computer="."
query="select LoadPercentage from Win32_Processor where DeviceID = 'CPU0'"
objWMIService = win32com.client .Dispatch("Wbem Scripting.SWbem Locator")
objSWbemService s = objWMIService.C onnectServer(co mputer,"root\ci mv2")
rows = objSWbemService s.ExecQuery(que ry)
print rows[0].LoadPercentage
import time
for count in xrange(4):
print objSWbemService s.ExecQuery(que ry)[0].LoadPercentage
time.sleep(1)
The microsoft docs on the info you can get on the processor is here: http://msdn.microsoft.com/library/de..._processor.asp
If you run this from a shell like PyCrust, you won't see anything for
four seconds, and then it will all show up.
What are you using for the text indexing? PyLucene???
-Jim
On 5/21/05, Donn Cave <do**@drizzle.c om> wrote: Quoth Mike Meyer <mw*@mired.org> : | "los" <ca******@gmail .com> writes: | > I'm trying to create a program similar to that of Google's desktop that | > will crawl through the hard drive and index files. I have written the | > program and as of now I just put the thread to sleep for 1 second after | > indexing a couple of files. | > | > I'm wondering if anyone knows of a way that I could make so that the | > program will run at full speed only runs after the computer has been | > idle for a while. I've looked at the "nice" command but that's not | > exactly what I want. | | On Unix, nice is exactly the answer. It's a lot more fine-grained than | what you're talking about, though. But it's the way things like | setiathome manage to run continuously without interfering with normal | usage. Well, he could certainly try it if he hasn't already, but I wouldn't be too surprised if it really isn't exactly what he wants. Maybe it depends on the scheduler, and maybe things have gotten a lot better in that department, but from my experience a process can be niced pretty hard and still tie up a lot of resources. A disk crawler sounds like a good example. I don't have any brilliant ideas, though. Your suggestion to use os.getloadavg sounds good to me. It might be kind of neat if there were some kind of APM ioctl that would register the calling process for notification of pending disk spin down, low power mode etc. Donn -- http://mail.python.org/mailman/listinfo/python-list
| ....
| I'm wondering if anyone knows of a way that I could make so that
| the program will run at full speed only runs after the computer
| has been idle for a while.
Perhaps looking at some ScreenSaver code could be useful ....
I've never considered how this is done myself,
but ScreeSavers seem to know that a user hasn't
done anything for a while ....
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
On Friday 20 May 2005 08:06 pm, los wrote: I'm wondering if anyone knows of a way that I could make so that the program will run at full speed only runs after the computer has been idle for a while. I've looked at the "nice" command but that's not exactly what I want.
You need to define what "idle" means: Screensavers do this in more
than one way, but typically, "idle" means "no user input has occured",
in which case you are looking for the time since the last input signal
from keyboard or mouse (not sure how to do this off the top of my
head, but that's the "screensave r" approach).
This is much less meaningful on a multiuser / multiple terminal
machine, of course. And it's really nonsense on a machine that is
also acting as a server. That's why "nice" seems like a more logical
solution for these types of machines.
Someone's already mentioned checking the load average, which
sounds like a good idea for your application.
--
Terry Hancock ( hancock at anansispacework s.com )
Anansi Spaceworks http://www.anansispaceworks.com
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
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/pyt...aver-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 <ca******@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
<snip>
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/pyt...aver-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 <ca******@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
"los" <ca******@gmail .com> writes: 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.
Actually, CPU usage going to 100% when you run a cpu-intensive program
under nice is what you expect - even want. The idea is that the nice'd
prog soaks up all the "unused" cpu on the system. You don't say whether
program B was niced or not, but from the description, it wasn't. And you
got the behavior I thought you wanted: the nice'd program quit using
any CPU at all while the normal program was running.
At least, that's the behavior I want from my backgrounded tasks.
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.
As has been pointed out, your daemon is doing disk i/o, which nice won't
mediate properly.
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.
Why 5 minutes? What if you've gone to get a cup of coffee while something
that takes more than five minutes is completing?
I'm sure there are tools for doing this kind of thing on windows. That's
pretty much how screen savers work. I haven't written a screen saver
for windows, though - so I have no idea what you're looking for.
Note that the screen savers I have written still lowered their priority
to avoid interfering with any long-running tasks you may be waiting on.
At least for CPU usage.
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.
I think you're right.
On a completely different topic, this looks like the wrong way to solve
the problem. You want to update a search engine based on changes to the
underlying file system. The right way to do this isn't to just keep
rescanning the file system, it's to arrange things so that your scanner
gets notified of any changes made to the file system. I did something like
this for my web site search engine, but that's hooked into the SCM that's
used for propogating changes to the web site. I know someone is working
on patches to the FreeBSD kernel to make this kind of thing work. It would
seem that some of the "backup" facilities that worked by keeping a mirror
of the disk on separate media would have to have used such hooks, but maybe
not.
I'm not sure this is possible. If it is, it's almost certainly deep magic.
<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Aubrey Hutchison |
last post by:
Using Python 2,3,2 with idle for developing programs
about 200 lines long. - Problem is not common to any specific program.
Program are rather simple with no trick programming. Usually no classes but
a few functions using math module with long integers.
Usually for the first few tryout everything works fine and
then idle locks "out" windows xp pro.. I can run other programs, but
clicking on idle icon gets me an hour glass for a few...
|
by: Michael Scarlett |
last post by:
There is an amazing article by paul graham about python, and an even
better discussion about it on slashdot. The reason I point this out,
is the more I read both articles, the more I realised how we would be
mutilating the language with that god forsaken @ decorator.
I don't know about the rest of you, but I learned python and fell in
love with its syntax and simplicity. Python - just works. So please
GVR. Don't complicate it. Leave it as...
|
by: Kevin Buchan |
last post by:
How can I tell if the system is 'idle', or the screen saver is
running, or the machine is locked?
I am writing an application that could really benefit from knowing
this information. During 'idle' time, I could do some of the slightly
heavier processing; during the 'working' time, I would display the
non-intrusive notifications that I don't want my customer to miss.
I see that I can apparently set the thread priority of my background...
|
by: John Salerno |
last post by:
If I want to write my code in a separate text editor (I like UltraEdit)
but then press a single button to have that code run in the IDLE
environment, is that possible? I know that you can configure UE to run
external tools, but I can't figure out how to run IDLE this way, because
when I check on its properties to find it's file path, it is just the
Python directory itself.
So not only do I not know where to find the actual file to run...
|
by: tony.ha |
last post by:
Hello,
I have open a Python program in the IDLE, but when I select the "run
module" under "run" menu, it
does not allow me to pass an argument to my Python program!
How do you pass an argument to a Python program under the IDLE? Thanks for
you help!
| |
by: Kurt B. Kaiser |
last post by:
Patch / Bug Summary
___________________
Patches : 385 open (+21) / 3790 closed (+21) / 4175 total (+42)
Bugs : 1029 open (+43) / 6744 closed (+43) / 7773 total (+86)
RFE : 262 open ( +4) / 291 closed ( +4) / 553 total ( +8)
New / Reopened Patches
______________________
|
by: mmm |
last post by:
I am looking for advice on Python Editors and IDEs
I have read other posts and threads on the subject and my two
questions at this time are mainly about the IDLE-like F5-run
facilities. While I am fairly happy using IDLE, the debugger is
unintuitive to me and I wanted a project manager and a better variable/
class browser and also the potential to edit/run other languages such
as R and Tex/Latex. Windows and LINUX compatibility is...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |