yr.save_state#
- yr.save_state(timeout_sec: int = 30) None[source]#
Used to save the instance status.
- Parameters:
timeout_sec (int, optional) – The timeout in seconds. Defaults to
30.- Returns:
None.
- Raises:
RuntimeError – If save_state is called in local mode, an exception is raised with the message: save_state is not called in local mode.
RuntimeError – If save_state is called in cloud mode without using the POSIX API, an exception is raised with the message: save_state is only called on cloud with POSIX API.
RuntimeError – If save_state fails to retrieve the saved instance state, an exception is raised with the message: Failed to save 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())}") >>> counter.save.invoke() >>> >>> counter.add.invoke() >>> print(f"member value after add one: {yr.get(counter.get.invoke())}") >>> >>> counter.load.invoke() >>> print(f"member value after load state(back to 0): {yr.get(counter.get.invoke())}")