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 41
41
import grp
42
42
except ImportError :
43
43
grp = None
44
+ try :
45
+ import resource
46
+ except ImportError :
47
+ resource = None
44
48
45
49
try :
46
50
import fcntl
@@ -1211,6 +1215,16 @@ def test_no_leaking(self):
1211
1215
max_handles = 1026 # too much for most UNIX systems
1212
1216
else :
1213
1217
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
1214
1228
handles = []
1215
1229
tmpdir = tempfile .mkdtemp ()
1216
1230
try :
@@ -1225,7 +1239,9 @@ def test_no_leaking(self):
1225
1239
else :
1226
1240
self .skipTest ("failed to reach the file descriptor limit "
1227
1241
"(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 ()
1229
1245
for i in range (10 ):
1230
1246
os .close (handles .pop ())
1231
1247
# Loop creating some subprocesses. If one of them leaks some fds,
You can’t perform that action at this time.
0 commit comments