CgroupHandle#

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

class zett_agent.sandbox.resources.CgroupHandle(path, applied=<factory>, dry_run=False)[source]#

One cgroup created for one run: it is created by the parent, joined by the child.

Parameters:
  • path (Path)

  • applied (dict[str, str])

  • dry_run (bool)

applied: dict[str, str]#

Limits the kernel accepted, keyed the way ResourceReport names them.

dry_run: bool = False#

True when this handle only answers what would happen, for capabilities(), and changes nothing.

set_memory(memory_bytes)[source]#

Cap the group’s memory and stop it from swapping its way around the cap.

Parameters:

memory_bytes (int)

Return type:

bool

set_cpu_percent(cpu_percent)[source]#

Give the group cpu_percent of one processor, as a quota per period.

Parameters:

cpu_percent (int)

Return type:

bool

set_processes(processes)[source]#

Cap how many processes and threads the group may hold.

Parameters:

processes (int)

Return type:

bool

join()[source]#

Move the calling process into this cgroup. Runs in the child before exec.

Writing 0 to cgroup.procs moves the writer, so the command and everything it starts are charged to this group from the first instruction on. Nothing is raised: the child has to reach exec.

Return type:

None

usage()[source]#

Read what the kernel recorded for the group.

Return type:

CgroupUsage

release()[source]#

Remove the cgroup directory, retrying briefly while its processes exit.

Return type:

bool