yr.instance#
- yr.instance(*args, **kwargs) InstanceCreator[source]#
Used to decorate classes that need to be remotely invoked on the openYuanRong system.
- Parameters:
class (class) – The class that needs to be remotely invoked.
invoke_options (yr.InvokeOptions) – Invocation parameters.
- Returns:
The creator of the decorated class. Data type is StatefulInstanceCreator.
- Raises:
RuntimeError – If the object decorated by instance is not a class.
Example
- Simple invocation example:
>>> import yr >>> yr.init() >>> >>> @yr.instance ... class Instance: ... sum = 0 ... def add(self, a): ... self.sum += a ... def get(self): ... return self.sum >>> >>> ins = Instance.invoke() >>> yr.get(ins.add.invoke(1)) >>> print(yr.get(ins.get.invoke())) 1 >>> ins.terminate() >>> >>> yr.finalize()
- Function invocation example:
>>> import yr >>> yr.init() >>> >>> @yr.instance ... class Instance: ... def __init__(self): ... self.sum = 0 ... def add(self, a): ... self.sum += a ... def get(self): ... return self.sum
>>> @yr.instance ... class Instance2: ... def __init__(self): ... self.ins = Instance.invoke() ... def add(self, a): ... return self.ins.add.invoke(a) ... def get(self): ... return yr.get(self.ins.get.invoke()) >>> >>> ins = Instance2.invoke() >>> yr.get(ins.add.invoke(2)) >>> print(yr.get(ins.get.invoke())) 2 >>> ins.terminate() >>> >>> yr.finalize()