How do I close the files from tempfile.mkstemp?

后端 未结 3 1513
灰色年华
灰色年华 2021-01-07 16:46

On my machine Linux machine ulimit -n gives 1024. This code:

from tempfile import mkstemp

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


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-07 17:37

    Use os.close() to close the file descriptor:

    import os
    from tempfile import mkstemp
    
    # Open a file
    fd, path = mkstemp()  
    
    # Close opened file
    os.close( fd )
    

提交回复
热议问题