yr.Group#
- class yr.Group(group_name: str = '', group_opts: GroupOptions | None = None)[source]#
Bases:
objectA class for managing the lifecycle of grouped instances.
The Group class is responsible for managing the lifecycle of grouped instances, including their creation and destruction. It follows the fate-sharing principle, where all instances in the group are created or destroyed together.
The Group class provides methods to create, terminate, suspend, resume, and manage grouped instances. It ensures that all instances in the group are treated as a single unit, and any failure during group creation will roll back the entire group.
Examples
>>> import yr >>> >>> yr.init() >>> >>> @yr.instance ... class Counter: ... sum = 0 ... ... def add(self, a): ... self.sum += a ... >>> group_opts = yr.GroupOptions() >>> group_name = "test" >>> g = yr.Group(group_name, group_opts) >>> opts = yr.InvokeOptions() >>> opts.group_name = group_name >>> ins = Counter.options(opts).invoke() >>> g.invoke() >>> res = ins.add.invoke() >>> print(yr.get(res)) >>> g.terminate() >>> >>> yr.finalize()
Attributes
Methods