los wrote: > 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 Windows: 1) You can use API calls in the win32file.ReadDirectoryChangesW() family to register to receive notification (event-based, not polling-based) of changes to one or more directory structures. 2) You can register to be informed X amount of time after the computer "becomes idle", as explained at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/taskschd/taskschd/idle_triggers.asp : """ An idle trigger is an event-based trigger that is fired a specific amount of time after the computer becomes idle. The computer is considered to be in an idle state when no keyboard or mouse input occurs. """ I haven't actually written any code to do this, but it appears to be accessible from Python via the win32com.taskscheduler.taskscheduler module; interface PyIScheduledWorkItem.[CreateTrigger(TASK_EVENT_TRIGGER_ON_IDLE) + SetIdleWait(...)]. There are related example programs in site-packages\win32comext\taskscheduler\test\test_addtask*.py 3) You can programmatically lower the priority of your process with win32process.SetPriorityClass(). --- So if you combine the three, you can create an indexing program that: a) Only operates when changes are actually made to the file system (no busy-wait). b) Defers all processing until the computer is "idle"; or also runs when the computer is not idle, yet yields priority to other processes; or runs under both conditions, but with a more aggressive priority when the computer is idle. -- http://mail.python.org/mailman/listinfo/python-list