John Machin wrote:

Test:
!for k in range(1000):
!    open('foo' + str(k), 'w')

I ran that and watched it open 2 million files and going strong ... until I figured that files are closed by Python immediately because there's no reference to them ;-)


Here's my code:

#!/usr/bin/env python
import os
print 'max number of file handles today is',
n = 0
h = []
try:
    while True:
        filename = 'mfh' + str(n)
        h.append((file(filename,'w'),filename))
        n = n + 1
except:
    print n
    for handle, filename in h:
        handle.close()
        os.remove(filename)

On Slackware 10.1, this yields 1021.
On WinXPSP2, this yields 509.

-pu
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to