yr.InstanceCreator.snapstart#
- InstanceCreator.snapstart(checkpoint_id: str) InstanceProxy[source]#
Start a new instance from a checkpoint snapshot.
This class method creates a new instance by restoring from a previously created snapshot. The new instance will have the same state as when the snapshot was taken.
- Parameters:
checkpoint_id (str) – The checkpoint ID returned by a previous snapshot() call. Format: {instanceID}-{functionID}-{uuid}
- Returns:
A new instance proxy for the restored instance.
- Return type:
- Raises:
RuntimeError – If the checkpoint does not exist or restore operation fails.
Example
>>> import yr >>> yr.init() >>> >>> @yr.instance ... class Counter: ... def __init__(self): ... self.value = 0 ... ... def increment(self): ... self.value += 1 ... return self.value ... ... def __yr_after_snapstart__(self): ... print(f"Restored with value={self.value}") ... >>> # Create instance and snapshot >>> ins = Counter.invoke() >>> yr.get(ins.increment.invoke()) # value = 1 >>> checkpoint_id = ins.snapshot(leave_running=False) >>> >>> # Restore from snapshot using the class >>> restored_ins = Counter.snapstart(checkpoint_id) >>> result = yr.get(restored_ins.increment.invoke()) # value = 2 >>> print(f"Value after restore: {result}") >>> >>> yr.finalize()