summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-10-22 04:47:07 (GMT)
committerGitHub <noreply@github.com>2021-10-22 04:47:07 (GMT)
commit8f6aa48cb2dc827a2cb76e35e91bf02d099875c5 (patch)
treef3ca1765ec77f9aa31deb0bc90d7866e3ef648f7 /Lib/test
parent9b3cda56870d087cf50f605e91f3d26964868640 (diff)
downloadcpython-8f6aa48cb2dc827a2cb76e35e91bf02d099875c5.zip
cpython-8f6aa48cb2dc827a2cb76e35e91bf02d099875c5.tar.gz
cpython-8f6aa48cb2dc827a2cb76e35e91bf02d099875c5.tar.bz2
bpo-43592: Raise RLIMIT_NOFILE in test.libregrtest (GH-29127)
Raise RLIMIT_NOFILE in test.libregrtest. On macOS the default is often too low for our testsuite to succeed. Co-authored by reviewer: Victor Stinner (cherry picked from commit 843b890334ca30cf6af27dffe29cecd06b49f7d9) Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/libregrtest/setup.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/libregrtest/setup.py b/Lib/test/libregrtest/setup.py
index 472c6eb..b791759 100644
--- a/Lib/test/libregrtest/setup.py
+++ b/Lib/test/libregrtest/setup.py
@@ -39,6 +39,7 @@ def setup_tests(ns):
for signum in signals:
faulthandler.register(signum, chain=True, file=stderr_fd)
+ _adjust_resource_limits()
replace_stdout()
support.record_original_stdout(sys.stdout)
@@ -134,3 +135,26 @@ def replace_stdout():
sys.stdout.close()
sys.stdout = stdout
atexit.register(restore_stdout)
+
+
+def _adjust_resource_limits():
+ """Adjust the system resource limits (ulimit) if needed."""
+ try:
+ import resource
+ from resource import RLIMIT_NOFILE, RLIM_INFINITY
+ except ImportError:
+ return
+ fd_limit, max_fds = resource.getrlimit(RLIMIT_NOFILE)
+ # On macOS the default fd limit is sometimes too low (256) for our
+ # test suite to succeed. Raise it to something more reasonable.
+ # 1024 is a common Linux default.
+ desired_fds = 1024
+ if fd_limit < desired_fds and fd_limit < max_fds:
+ new_fd_limit = min(desired_fds, max_fds)
+ try:
+ resource.setrlimit(RLIMIT_NOFILE, (new_fd_limit, max_fds))
+ print(f"Raised RLIMIT_NOFILE: {fd_limit} -> {new_fd_limit}")
+ except (ValueError, OSError) as err:
+ print(f"Unable to raise RLIMIT_NOFILE from {fd_limit} to "
+ f"{new_fd_limit}: {err}.")
+