为什么python的文件句柄数有限制?
发布于 2021-01-29 19:32:00
我编写了简单的代码进行测试,可能会在python脚本中打开多少文件:
for i in xrange(2000):
fp = open('files/file_%d' % i, 'w')
fp.write(str(i))
fp.close()
fps = []
for x in xrange(2000):
h = open('files/file_%d' % x, 'r')
print h.read()
fps.append(h)
我有一个例外
IOError: [Errno 24] Too many open files: 'files/file_509'
关注者
0
被浏览
152
1 个回答