Why python has limit for count of file handles?

前端 未结 6 623
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 05:38

I writed simple code for test, how much files may be open in python script:

for i in xrange(2000):
    fp = open(\'files/file_%d\' % i, \'w\')
    fp.write(s         


        
6条回答
  •  面向向阳花
    2020-11-27 06:06

    The number of open files is limited by the operating system. On linux you can type

    ulimit -n
    

    to see what the limit is. If you are root, you can type

    ulimit -n 2048
    

    now your program will run ok (as root) since you have lifted the limit to 2048 open files

提交回复
热议问题