yr.load_state#
- yr.load_state(timeout_sec: int = 30) None[source]#
Used to load the saved instance state.
- Parameters:
timeout_sec (int, optional) – The timeout in seconds. Defaults to
30.- Returns:
None.
- Raises:
RuntimeError – If load_state is not called in local mode, an exception is raised with the message: load_state is not called in local mode.
RuntimeError – If load_state is called in cloud mode without using the POSIX API, an exception is raised with the message: load_state is only supported on cloud with POSIX API.
RuntimeError – If load_state fails to retrieve the saved instance state, an exception is raised with the message: Failed to load state.
Example
>>> @yr.instance ... class Counter: ... def __init__(self): ... self.cnt = 0 ... ... def add(self): ... self.cnt += 1 ... return self.cnt ... ... def get(self): ... return self.cnt ... ... def save(self, timeout=30): ... yr.save_state(timeout) ... ... def load(self, timeout=30): ... yr.load_state(timeout) ... >>> counter = Counter.invoke() >>> print(f"member value before save state: {yr.get(counter.get.invoke())}") member value before save state: 0 >>> counter.save.invoke() >>> >>> counter.add.invoke() >>> print(f"member value after add one: {yr.get(counter.get.invoke())}") member value after add one: 1 >>> >>> counter.load.invoke() >>> print(f"member value after load state(back to 0): {yr.get(counter.get.invoke())}") member value after load state(back to 0): 0