MCPcopy Create free account
hub / github.com/python/cpython / adjust_rlimit_nofile

Function adjust_rlimit_nofile

Lib/test/libregrtest/utils.py:568–591  ·  view source on GitHub ↗

On macOS the default fd limit (RLIMIT_NOFILE) is sometimes too low (256) for our test suite to succeed. Raise it to something more reasonable. 1024 is a common Linux default.

()

Source from the content-addressed store, hash-verified

566
567
568def adjust_rlimit_nofile() -> None:
569 """
570 On macOS the default fd limit (RLIMIT_NOFILE) is sometimes too low (256)
571 for our test suite to succeed. Raise it to something more reasonable. 1024
572 is a common Linux default.
573 """
574 try:
575 import resource
576 except ImportError:
577 return
578
579 fd_limit, max_fds = resource.getrlimit(resource.RLIMIT_NOFILE)
580
581 desired_fds = 1024
582
583 if fd_limit < desired_fds and fd_limit < max_fds:
584 new_fd_limit = min(desired_fds, max_fds)
585 try:
586 resource.setrlimit(resource.RLIMIT_NOFILE,
587 (new_fd_limit, max_fds))
588 print(f"Raised RLIMIT_NOFILE: {fd_limit} -> {new_fd_limit}")
589 except (ValueError, OSError) as err:
590 print_warning(f"Unable to raise RLIMIT_NOFILE from {fd_limit} to "
591 f"{new_fd_limit}: {err}.")
592
593
594def get_host_runner() -> str:

Callers 1

setup_processFunction · 0.85

Calls 1

print_warningFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…