我在追加模式下打开一个文件,然后在循环中写入它 但是我在一段时间后遇到了这个错误并且我的脚本死了。
这就是我的运作
python monitor_free.py ucs107-cip-m 86400&
我的脚本就像这样
import sys
import time
from sp_cluster import SpCluster
clusterip = sys.argv[1]
timeout = int(sys.argv[2])
cl = SpCluster(str(clusterip))
x = cl.stctlvms
f = open("free_stat.txt", "a")
start_time = time.time()
elapsed = 0
seperator = "*" * 79
while(elapsed < timeout):
for vm in x:
text, _, _ = vm.ssh_cmd("free -ko -bm")
dates, _, _ = vm.ssh_cmd("date")
f.write(seperator)
f.write("\n")
f.write(str(vm.fqdn))
f.write("\n")
f.write(str(dates))
f.write("\n")
f.write(str(text))
f.write("\n")
time.sleep(10)
elapsed = time.time() - start_time
我的理解是,应该只有一个fd一直打开......但似乎是错误的......有谁知道发生了什么?
paramiko抛出错误
ERROR: Unknown exception: [Errno 24] Too many open files: '/dev/urandom'
ERROR: Traceback (most recent call last):
ERROR: File "/usr/local/lib/python2.7/dist- packages/paramiko/transport.py", line 1719, in run
ERROR: File "/usr/local/lib/python2.7/dist-packages/paramiko/transport.py", line 1909, in _send_kex_init
ERROR: OSError: [Errno 24] Too many open files: '/dev/urandom'