使用 python 2.7
import time, os
def foo():
try:
a=0
while 1:
os.system("bash command")
a += 1
time.sleep(1/30)
print a
except KeyboardInterrupt:
print "Interrupted!"
foo()
我正在从 Ubuntu 12.04 64 位下的终端运行它,但我无法停止这个无限循环,为什么它不起作用?
我想有一个无限循环,只有当用户按下某个特定键或任何键时才打破它。