Please look at the following code:
for i in xrange(1,5000):
with open(r'test\test%s.txt' % i, 'w') as qq:
qq.write('aa'*3000)
It seems to be written according to all Python rules; files are closing after using. Seems to. But in fact it seems to recommend(!) system to close file, not to close it explicitly because when I'm looking on Resource monitor it shows a lot of open files . It gives me a lot of problems because in my script I use a lot of files and after a long time I got "Too many open files" error despite of 'closing' it from source code.
Is there some way to explicitly close file in Python? Or how can I check whether the file was really(!) closed or not?
Update: I've just tried with another monitoring tool - Handle from Sysinternals and it shows all correct and I trust it. So, it may be problem in Resource monitor itself.
Screenshot which shows files opened: