Skip to content

Commit ff9198d

Browse files
[3.13] pythongh-124986: Fix test_no_leaking in test_subprocess on NetBSD and FreeBSD (pythonGH-132476) (pythonGH-132498)
On platforms where the file descriptor limit is larger than FD_SETSIZE that test was always skipped (FreeBSD) or always failing (NetBSD). (cherry picked from commit f7b24ff) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent f206b98 commit ff9198d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Lib/test/test_subprocess.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
import grp
4141
except ImportError:
4242
grp = None
43+
try:
44+
import resource
45+
except ImportError:
46+
resource = None
4347

4448
try:
4549
import fcntl
@@ -1210,6 +1214,16 @@ def test_no_leaking(self):
12101214
max_handles = 1026 # too much for most UNIX systems
12111215
else:
12121216
max_handles = 2050 # too much for (at least some) Windows setups
1217+
if resource:
1218+
# And if it is not too much, try to make it too much.
1219+
try:
1220+
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
1221+
if soft > 1024:
1222+
resource.setrlimit(resource.RLIMIT_NOFILE, (1024, hard))
1223+
self.addCleanup(resource.setrlimit, resource.RLIMIT_NOFILE,
1224+
(soft, hard))
1225+
except (OSError, ValueError):
1226+
pass
12131227
handles = []
12141228
tmpdir = tempfile.mkdtemp()
12151229
try:
@@ -1224,7 +1238,9 @@ def test_no_leaking(self):
12241238
else:
12251239
self.skipTest("failed to reach the file descriptor limit "
12261240
"(tried %d)" % max_handles)
1227-
# Close a couple of them (should be enough for a subprocess)
1241+
# Close a couple of them (should be enough for a subprocess).
1242+
# Close lower file descriptors, so select() will work.
1243+
handles.reverse()
12281244
for i in range(10):
12291245
os.close(handles.pop())
12301246
# Loop creating some subprocesses. If one of them leaks some fds,

0 commit comments

Comments
 (0)