I wrote a simple code to test how many files may be open in python script:
for i in xrange(2000):
fp = open('files/file_%d' % i, 'w')
fp.write(str(i))
fp.close()
fps = []
for x in xrange(2000):
h = open('files/file_%d' % x, 'r')
print h.read()
fps.append(h)
and I get the exception:
IOError: [Errno 24] Too many open files: 'files/file_509'
try..finallyorwithto safely close a file. To your problem: maybe you want to tell us what you are going to do because want your code does makes no sense at all for me.ulimit -ngives me 1024. I think you need to count also/usr/lib64/python2.7/atexit.pyand/home/xyz/.pystartupas opened files.