How do I close the files from tempfile.mkstemp?

后端 未结 3 1534
灰色年华
灰色年华 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:49

    Since mkstemp() returns a raw file descriptor, you can use os.close():

    import os
    from tempfile import mkstemp
    
    for n in xrange(1024 + 1):
        f, path = mkstemp()
        # Do something with 'f'...
        os.close(f)
    

提交回复
热议问题