Como fecho os arquivos do tempfile.mkstemp?

Na minha máquina Linux machineulimit -n1024. Este código:

from tempfile import mkstemp

for n in xrange(1024 + 1):
    f, path = mkstemp()    

falha no loop da última linha com:

Traceback (most recent call last):
  File "utest.py", line 4, in <module>
  File "/usr/lib/python2.7/tempfile.py", line 300, in mkstemp
  File "/usr/lib/python2.7/tempfile.py", line 235, in _mkstemp_inner
OSError: [Errno 24] Too many open files: '/tmp/tmpc5W3CF'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 64, in apport_excepthook
ImportError: No module named fileutils

Parece que abri para muitos arquivos - mas otype dof epath são simplesmenteint estr então não sei como fechar cada arquivo que abri.Como fecho os arquivos do tempfile.mkstemp?

questionAnswers(6)

yourAnswerToTheQuestion