仅在空闲时间运行python程序 [英] Running a python program during idle time only

查看:80
本文介绍了仅在空闲时间运行python程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试创建类似于谷歌桌面的程序,

将爬过硬盘和索引文件。我已经编写了

程序,截至目前我只是让线程在

索引几个文件后暂停1秒钟。


我想知道是否有人知道我可以制作的方式,以便

程序将以全速运行,仅在计算机运行后运行

闲置一会儿。我看过好看的命令,但那不是

正是我想要的。


如果不清楚我上面解释的内容,请告诉我。


谢谢

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

推荐答案

" los" < CA ****** @ gmail.com>写道:
"los" <ca******@gmail.com> writes:
我正在尝试创建一个类似于谷歌桌面的程序,它将抓取硬盘和索引文件。我已经编写了
程序,到目前为止,我只是让线程在索引几个文件后暂停1秒钟。

我想知道是否有人知道我可以做的一种方式,使得
程序将以全速运行,只有在计算机闲置一段时间后才会运行。我看过好看的命令,但那不是我想要的。
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.




在Unix上,不错的是答案。不过,你所谈论的内容要比

更精细。但这就像

setiathome这样的方式可以连续运行而不会干扰正常的

使用。


如果是这样的话为了你的细粒度,你可以尝试每隔几个小时醒来并检查平均负载(通过os.getloadavg),并且只有

做工作如果负载平均值低 - 比小于0.5。当

运行时,你每隔几分钟检查一次平均负载并停止

如果它明显高于1(你)。这种方法存在的问题是,它不能很好地处理这样做的多个工具。即 - 如果

你运行setiathome,你的平均负载总是高于1,所以你需要调整你的支票价值以考虑其他任何事情

可能在后台。尼斯自动处理这个问题。


< mike

-

Mike Meyer< mw*@mired.org> http://www.mired.org/home/mwm/

独立的WWW / Perforce / FreeBSD / Unix顾问,电子邮件以获取更多信息。



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.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.


Quoth Mike Meyer< mw*@mired.org>:

| "洛斯" < CA ****** @ gmail.com>写道:

| >我正在尝试创建一个类似于Google桌面的程序

| >将遍历硬盘和索引文件。我写了

| >程序和截至目前我只是让线程在

|之后休眠1秒>索引几个文件。

| >

| >我想知道是否有人知道我可以制作的方式以便

| >程序将以全速运行,仅在计算机运行后运行

| >闲着一会儿。我看过好看的命令,但那不是

| >正是我想要的。

|

|在Unix上,好的就是答案。它比

|更精细但是你在谈论什么。但这就像

|的方式setiathome设法连续运行而不会干扰正常

|用法。


嗯,如果他还没有,他当然可以尝试一下,但如果它真的没有,我就不会感到惊讶他正是他想要的。也许它

取决于调度程序,也许事情已经变得更好

在该部门,但根据我的经验,一个过程可以很好地结合

很难并且仍然占用了大量资源。磁盘爬虫听起来像

就是一个很好的例子。


但我没有任何好主意。你的建议使用

os.getloadavg对我来说听起来不错。如果

是某种APM ioctl会注册调用进程

来通知待处理磁盘降速,低功耗模式等,它可能会有点整洁。 br />

Donn
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


可能有一种方法可以判断用户已经闲置了多长时间,但是这里有

如何检查CPU负载以查看它是否升高...(当然

你的程序也可能提升它。)


在linux上,你可以从/ proc / loadavg读取


这是尝试Windows的一个有趣的事情......


确保你安装了win32all软件包...


import win32com.client

computer ="。"

query ="从Win32_Processor中选择LoadPercentage,其中DeviceID =''CPU0''"

objWMIService = win32com.client.Dispatch(" WbemScripting.SWbemLocat or)

objSWbemServices = objWMIService.ConnectServer(电脑,root \ cimv2)

rows = objSWbemServices.ExecQuery(查询)

打印行[0] .LoadPercentage


导入时间

$ x $ b for xrange(4):

print objSWbemServices.ExecQuery(query)[0] .LoadPercentage

time.sleep(1)


关于处理器上可以获得的信息的微软文档在这里:
http://msdn.microsoft.com/library/ de ..._ processor.asp


如果你从像PyCrust这样的shell运行它,你什么都看不到

四秒,然后它都会显示出来。


您使用什么来进行文本索引? PyLucene ???


-Jim


2005年5月21日,Donn Cave< do ** @ drizzle.com>写道:
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("WbemScripting.SWbemLocat or")
objSWbemServices = objWMIService.ConnectServer(computer,"root\cimv2")
rows = objSWbemServices.ExecQuery(query)
print rows[0].LoadPercentage

import time

for count in xrange(4):
print objSWbemServices.ExecQuery(query)[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.com> wrote:
Quoth Mike Meyer< mw*@mired.org>:
| "洛斯" < CA ****** @ gmail.com>写道:
| >我正在尝试创建一个类似于谷歌桌面的程序
| >将遍历硬盘和索引文件。我写了
| >程序和截至目前我只是让线程在
|之后休眠1秒钟>索引几个文件。
| >
| >我想知道是否有人知道我可以制作的方式以便
| >程序将以全速运行,仅在计算机运行后运行>闲着一会儿。我看过好看的命令,但那不是
| >正是我想要的。
|
|在Unix上,好的就是答案。它比
|更精细但是你在谈论什么。但这就像是
| setiathome设法连续运行而不会干扰正常
|用法。

好吧,如果他还没有,他当然可以尝试一下,但如果真的不是他想要的话,我也不会太惊讶。也许它取决于调度程序,也许事情已经在那个部门中变得更好了,但根据我的经验,一个过程可以很好地结合,并且仍然占用大量资源。磁盘爬虫听起来像是一个很好的例子。

我没有任何好主意。您使用
os.getloadavg的建议对我来说听起来不错。如果某种APM ioctl可以注册调用进程
通知挂起磁盘降速,低功耗模式等,它可能有点整洁。

Donn
-
http:// mail。 python.org/mailman/listinfo/python-list
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



这篇关于仅在空闲时间运行python程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆