Skip to content

ANTA Settings

anta.settings

Settings for ANTA.

DEFAULT_MAX_CONCURRENCY module-attribute

DEFAULT_MAX_CONCURRENCY = 50000

Default value for the maximum number of concurrent tests in the event loop.

DEFAULT_NOFILE module-attribute

DEFAULT_NOFILE = 16384

Default value for the maximum number of open file descriptors for the ANTA process.

AntaRunnerSettings

Bases: BaseSettings

Environment variables for configuring the ANTA runner.

When initialized, relevant environment variables are loaded. If not set, default values are used.

On POSIX systems, also adjusts the process soft limit based on the ANTA_NOFILE environment variable while respecting the system hard limit, meaning the new soft limit cannot exceed the system’s hard limit.

On non-POSIX systems (Windows), sets the limit to sys.maxsize.

The adjusted limit is available with the file_descriptor_limit property after initialization.

Attributes:

Name Type Description
nofile PositiveInt

Environment variable: ANTA_NOFILE

The maximum number of open file descriptors for the ANTA process. Defaults to 16384.

max_concurrency PositiveInt

Environment variable: ANTA_MAX_CONCURRENCY

The maximum number of concurrent tests that can run in the event loop. Defaults to 50000.

file_descriptor_limit property
file_descriptor_limit: PositiveInt

The maximum number of file descriptors available to the process.

model_post_init
model_post_init(_context: Any) -> None

Post-initialization method to set the file descriptor limit for the current ANTA process.

Source code in anta/settings.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def model_post_init(self, _context: Any) -> None:  # noqa: ANN401
    """Post-initialization method to set the file descriptor limit for the current ANTA process."""
    if os.name != "posix":
        logger.warning("Running on a non-POSIX system, cannot adjust the maximum number of file descriptors.")
        self._file_descriptor_limit = sys.maxsize
        return

    import resource

    limits = resource.getrlimit(resource.RLIMIT_NOFILE)
    logger.debug("Initial file descriptor limits for the current ANTA process: Soft Limit: %s | Hard Limit: %s", limits[0], limits[1])

    # Set new soft limit to minimum of requested and hard limit
    new_soft_limit = min(limits[1], self.nofile)
    logger.debug("Setting file descriptor soft limit to %s", new_soft_limit)
    try:
        resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft_limit, limits[1]))
    except ValueError as exception:
        logger.warning("Failed to set file descriptor soft limit for the current ANTA process: %s", exc_to_str(exception))

    self._file_descriptor_limit = resource.getrlimit(resource.RLIMIT_NOFILE)[0]