I created 10000 files – my default limit was ” ulimit -n 1024″ – I expected following script to fail with a message like “Too many files open” , but it didn’t fail. (/tmp/files has 10000 files)
Any thoughts on where am i going wrong?
import os
listfiles=os.listdir('/tmp/files')
count=0
f=''
for file in listfiles:
fn=f+str(count)
fn=open(file,'w')
fn.write('hello')
print 'file=',file
count=count+1
print count
Every time you rebind
fnthe previous file gets closed. It’s possible that in jython for example the file doesn’t get closed immediately, but it very likely will still be garbarge collected and closed before you exceed the 1024 file limitTry storing the file objects in a list like this: