dummynet.CGroup

class dummynet.CGroup(name: str, shell, log, cpu_limit=None, memory_limit=None)

A class for manipulating cgroups. This class is not meant to be used directly, but through the DummyNet-instance.

Parameters:
  • name – The name of the cgroup.

  • shell – The shell object used for executing shell commands.

  • log – The log object used for logging messages.

  • cpu_limit – The ratio of CPU usage limit for the cgroup. Between 0 and 1. Defaults to None.

  • memory_limit – The memory usage hard-limit for the cgroup. In bytes. Defaults to None. if memory usage exceeds the limit, the processes will get killed by the kernel. OOM.

__init__(name: str, shell, log, cpu_limit=None, memory_limit=None) None
add_pid(pid)

Add a Process to the specified cgroup.

Parameters:

args – The process ID.

delete_cgroup(not_exist_ok=False)

Delete the specified cgroup.

Parameters:

not_exist_ok – If True, ignore if cgroup does not exist, otherwise raise Exception if does not exist. Defaults to False.

hard_clean()

Cleanup the cgroup by removing the pid from cgroup.procs and deleting the cgroup.

make_cgroup(exist_ok=False)

Create a cgroup with the specified name.

Parameters:

exist_ok – If True, force overwrite the existing cgroup, otherwise raise Exception if it already exists. Defaults to False.

set_limit(controller_dict: dict)

Set the usage limit for a specific controller in the cgroup.

Parameters:

controller_dict – Dictionary of controllers as keys and limits as values.

Available controllers to limit:

  • cpu (percentage) -> (0, 1]

  • memory (bytes) -> (0, max].