mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-124986: Fix test_no_leaking in test_subprocess on NetBSD and FreeBSD (GH-132476)
On platforms where the file descriptor limit is larger than FD_SETSIZE that test was always skipped (FreeBSD) or always failing (NetBSD).
This commit is contained in:
parent
1fc1df8dcc
commit
f7b24ffefd
1 changed files with 17 additions and 1 deletions
|
@ -41,6 +41,10 @@ try:
|
||||||
import grp
|
import grp
|
||||||
except ImportError:
|
except ImportError:
|
||||||
grp = None
|
grp = None
|
||||||
|
try:
|
||||||
|
import resource
|
||||||
|
except ImportError:
|
||||||
|
resource = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import fcntl
|
import fcntl
|
||||||
|
@ -1211,6 +1215,16 @@ class ProcessTestCase(BaseTestCase):
|
||||||
max_handles = 1026 # too much for most UNIX systems
|
max_handles = 1026 # too much for most UNIX systems
|
||||||
else:
|
else:
|
||||||
max_handles = 2050 # too much for (at least some) Windows setups
|
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 = []
|
handles = []
|
||||||
tmpdir = tempfile.mkdtemp()
|
tmpdir = tempfile.mkdtemp()
|
||||||
try:
|
try:
|
||||||
|
@ -1225,7 +1239,9 @@ class ProcessTestCase(BaseTestCase):
|
||||||
else:
|
else:
|
||||||
self.skipTest("failed to reach the file descriptor limit "
|
self.skipTest("failed to reach the file descriptor limit "
|
||||||
"(tried %d)" % max_handles)
|
"(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):
|
for i in range(10):
|
||||||
os.close(handles.pop())
|
os.close(handles.pop())
|
||||||
# Loop creating some subprocesses. If one of them leaks some fds,
|
# Loop creating some subprocesses. If one of them leaks some fds,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue