1

I am opening a file in append mode once and then writing to it in a loop But I hit this error after a while and my script dies.

This is what I run

python monitor_free.py ucs107-cip-m 86400 &

My script goes like this

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

My understanding was that there should only be one fd open the whole time....but seems like its wrong... anyone knows whats happening?

Error is thrown by 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'
JATMON
  • 1,000
  • 1
  • 8
  • 14
  • What are the ** marking on the line where you open the file? – joel goldstick Oct 07 '16 at 18:50
  • How many times have you run this script? It could be leaving a file open each time. It's hard to say without seeing what you are doing with Paramiko. – Joseph LeClerc Oct 07 '16 at 18:54
  • i may have run this 5-10 times max, but i kill the process before i restart – JATMON Oct 07 '16 at 18:57
  • It's not necessarily a limit on number of times *that particular* file is open -- can just as easily be a limit on the file descriptor table size. Anyhow, when this is happening (before the interpreter exits -- consider using `python -i` to prevent such), use `lsof` or `ls -l /proc//fd` to see which and how many FDs are open. – Charles Duffy Oct 07 '16 at 19:12
  • BTW, your indentation is definitely wrong -- this is showing no indent after `for vm in x:` – Charles Duffy Oct 07 '16 at 19:14
  • 1
    ...and every network socket eats a file descriptor, so it's under no circumstances only one. – Charles Duffy Oct 07 '16 at 19:14
  • 1
    That was the case, we weren't closing the connections in our SSH library.. thanks Charles – JATMON Oct 07 '16 at 22:10

0 Answers0