Skip to content

Commit b228f62

Browse files
committed
Raise RLIMIT_NOFILE in test.regrtest.
On macOS the default is often too low for our testsuite to succeed.
1 parent 311910b commit b228f62

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/libregrtest/main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,24 @@ def cleanup(self):
633633
print("Remove file: %s" % name)
634634
os_helper.unlink(name)
635635

636+
def adjust_resource_limits(self):
637+
try:
638+
import resource
639+
from resource import RLIMIT_NOFILE, RLIM_INFINITY
640+
except ImportError:
641+
return
642+
fd_limit, max_fds = resource.getrlimit(RLIMIT_NOFILE)
643+
if fd_limit < 2000 and fd_limit < max_fds:
644+
# On macOS the default fd limit is sometimes too low (256) for our
645+
# test suite to succeed. Raise it to something more reasonable.
646+
new_fd_limit = min(2000, max_fds)
647+
try:
648+
resource.setrlimit(RLIMIT_NOFILE, (new_fd_limit, max_fds))
649+
print(f"Raised RLIMIT_NOFILE to {new_fd_limit}.")
650+
except (ValueError, OSError) as err:
651+
print(f"Unable to raise RLIMIT_NOFILE from {fd_limit} to "
652+
f"{new_fd_limit}: {err}".)
653+
636654
def main(self, tests=None, **kwargs):
637655
self.parse_args(kwargs)
638656

0 commit comments

Comments
 (0)