首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

写了一个依据cpu使用率 发声的小程序

2012-09-14 
写了一个根据cpu使用率 发声的小程序.下午烦躁,躺着睡觉想起来前天看黑客帝国,第6分50秒,neo的电脑发出一

写了一个根据cpu使用率 发声的小程序.

下午烦躁,躺着睡觉

想起来前天看黑客帝国,第6分50秒,neo的电脑发出一种beep,觉得很酷

想弄在一把

?

于是写了个代码:

它会 根据cpu使用率 发声

cpu usage ? ? ? ? ? 2秒内发声情况

10% ? ? ? ? ? ? ? ? ? ?. (2声)

20% ? ? ? ? ? ? ? ? ? ?..(4声)

...

100% ? ? ? ? ? ? ? ? ? ?....................(20声)

?

于是乎,如果cpu使用率接近100%的话,她就会不停的发声:)

?

?

?

#!/usr/bin/env python2.6#coding=utf8#<<neo>>  06:45-6:55 beep ...  ... .....#if the cpu usage is full ,the beep will not stop. # usage:#    sudo modprobe pcspkr#    sudo apt-get install beepimport osimport re, timedef beep(frequency, duration=100, repeat=10, delay=10): #100 ms    cmd = 'beep -f %s -l %s -r %s -d %s' % (frequency,duration, repeat, delay)    print cmd    os.system(cmd)last_all = 0last_used = 0def cpu_usage():    str = file('/proc/stat').read()    arr = re.split(r'\s+', str)[1:5]    print arr    arr = [int(item) for item in arr]    print arr    cpu_all = sum(arr)    cpu_used = sum(arr[0:3])    usage = 1.0 * (cpu_used- last_used) / (cpu_all - last_all)    global last_used, last_all    last_all = cpu_all    last_used = cpu_used    print usage    return usagefor i in range (0, 100000):    usage = cpu_usage()    t1 = time.time()    beep(80, 10, int(usage * 20)+1, 100) #beep for (usage*10+10) times, will tack 1s-2s    t2 = time.time()    print t1, t2    time.sleep(2-(t2-t1))  #2s sub the time used in beep

?

?

1 楼 idning 2010-05-22   黑客帝国I背景音乐:
这是一部所有的背景音乐,在百度里搜吧
第一部:
1. Main Title
2. Trinity Infinity
3. Follow Instructions
4. The White Rabbit
5. Sneak Rue Eve
6. Unable to Speak
7. Road To Truthville
8. The Lafayette Mirror
9. The Power Plant
10. Welcome to the Real World
11. Introductions
12. The Truth
13. No Return
14. Training (Bow Whisk Orchestra)
15. Switch or Break Show
16. The Jump Program
17. I Don't Remember You Bringing me Dinner
18. The Sewers
19. Want a Drink?/The Turncoat
20. Departure & Arrival
21. Spoonboy Sermon
22. Oracle Honesty
23. The Hotel Ambush- Exit Mr. Hat
24. Cypher Punk
25. Think Tank
26. A Virus
27. Let's Go
28. Bullet-time
29. You Move Like They Do
30. Ontological Shock
31. The Subway Fight
32. Neo on the Run
33. Anything is Possible


电脑对他说“。。。跟随白兔。。”之前,他躺在床上时听的音乐。
dissolved girl

热点排行