File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 4141 import grp
4242except ImportError :
4343 grp = None
44+ try :
45+ import resource
46+ except ImportError :
47+ resource = None
4448
4549try :
4650 import fcntl
@@ -1211,6 +1215,16 @@ def test_no_leaking(self):
12111215 max_handles = 1026 # too much for most UNIX systems
12121216 else :
12131217 max_handles = 2050 # too much for (at least some) Windows setups
1218+ if resource :
1219+ # And if it is not too much, try to make it too much.
1220+ try :
1221+ soft , hard = resource .getrlimit (resource .RLIMIT_NOFILE )
1222+ if soft > 1024 :
1223+ resource .setrlimit (resource .RLIMIT_NOFILE , (1024 , hard ))
1224+ self .addCleanup (resource .setrlimit , resource .RLIMIT_NOFILE ,
1225+ (soft , hard ))
1226+ except (OSError , ValueError ):
1227+ pass
12141228 handles = []
12151229 tmpdir = tempfile .mkdtemp ()
12161230 try :
@@ -1225,7 +1239,9 @@ def test_no_leaking(self):
12251239 else :
12261240 self .skipTest ("failed to reach the file descriptor limit "
12271241 "(tried %d)" % max_handles )
1228- # Close a couple of them (should be enough for a subprocess)
1242+ # Close a couple of them (should be enough for a subprocess).
1243+ # Close lower file descriptors, so select() will work.
1244+ handles .reverse ()
12291245 for i in range (10 ):
12301246 os .close (handles .pop ())
12311247 # Loop creating some subprocesses. If one of them leaks some fds,
You can’t perform that action at this time.
0 commit comments