#!/usr/bin/env python # file_limits_bug.py # # Created by George King on 12/11/09. from __future__ import print_function import resource # get the default limit for the number of open files default_limits = resource.getrlimit(resource.RLIMIT_NOFILE) print("default file limits:", default_limits) # double the default soft limit test_limit = default_limits[0] * 2 assert(test_limit < default_limits[1]) # test soft limit should be less than the hard limit # set the soft limit; -1 sets hard limit to max possible resource.setrlimit(resource.RLIMIT_NOFILE, (test_limit, -1)) print("new file limits:", resource.getrlimit(resource.RLIMIT_NOFILE)) # open test files up to the limit - 3 (accounts for stdin, stdout, and stderr) test_names = ["testfiles/testfile%03d" % (i,) for i in range(test_limit - 3)] files = [] for n in test_names: files.append(open(n, 'w'))