import grp
except ImportError:
grp = None
+try:
+ import resource
+except ImportError:
+ resource = None
try:
import fcntl
max_handles = 1026 # too much for most UNIX systems
else:
max_handles = 2050 # too much for (at least some) Windows setups
+ if resource:
+ # And if it is not too much, try to make it too much.
+ try:
+ soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
+ if soft > 1024:
+ resource.setrlimit(resource.RLIMIT_NOFILE, (1024, hard))
+ self.addCleanup(resource.setrlimit, resource.RLIMIT_NOFILE,
+ (soft, hard))
+ except (OSError, ValueError):
+ pass
handles = []
tmpdir = tempfile.mkdtemp()
try:
else:
self.skipTest("failed to reach the file descriptor limit "
"(tried %d)" % max_handles)
- # Close a couple of them (should be enough for a subprocess)
+ # Close a couple of them (should be enough for a subprocess).
+ # Close lower file descriptors, so select() will work.
+ handles.reverse()
for i in range(10):
os.close(handles.pop())
# Loop creating some subprocesses. If one of them leaks some fds,