plan_rlimits#

Run commands and agent-written programs inside an operating-system boundary. See the guide.

zett_agent.sandbox.resources.plan_rlimits(limits, *, supported=None, user_tasks=None)[源代码]#

Turn the POSIX limits into setrlimit calls, and say what cannot be applied.

A requested value above the machine's hard limit is lowered to it with a warning rather than failing: the hard limit is already a ceiling the process cannot pass, so the request cannot be honoured as written and the caller is told. core_dumps is off unless asked for, so it appears in almost every plan. cpu_percent has no POSIX limit and is left to the cgroup.

Two limits are not applied as written:

  • cpu_seconds sets the hard limit one second above the soft one. With the two equal, Linux skips SIGXCPU and kills the process with SIGKILL, so the run could not say it hit the limit; with a second between them the process is ended by SIGXCPU at the limit, and the hard limit still stops one that handles it.

  • processes is the number of processes the command may add. The kernel compares RLIMIT_NPROC with every process the user owns, so the limit is that count plus the request. Taking the number literally would stop every command on a machine where the user already runs more than that. Other processes of the same user that start during the run use up the same allowance, which is why a cgroup, where one is available, is preferred.

参数:
  • user_tasks (int | None) -- The user's current process count; counted here when None.

  • limits (ResourceLimits)

  • supported (frozenset[str] | None)

返回类型:

tuple[tuple[RlimitStep, ...], tuple[str, ...]]