yr.InstanceProxy.snapstart#
- InstanceProxy.snapstart(checkpoint_id: str) InstanceProxy[source]#
Start a new instance from a snapshot.
This method creates a new instance by restoring from a previously created snapshot, sending signal 19 (INSTANCE_SNAPSTART_SIGNAL) through the Kill interface. The new instance will have the same state as when the snapshot was taken.
- Parameters:
checkpoint_id (str) – The checkpoint ID returned by the snapshot() method. 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 MyInstance: ... def __init__(self): ... self.counter = 0 ... ... def increment(self): ... self.counter += 1 ... return self.counter ... ... def __yr_after_snapstart__(self): ... print(f"Instance restored, counter={self.counter}") ... >>> # Create instance and snapshot >>> ins = MyInstance.invoke() >>> yr.get(ins.increment.invoke()) # counter = 1 >>> checkpoint_id = ins.snapshot(leave_running=False) >>> >>> # Restore from snapshot >>> restored_ins = MyInstance.snapstart(checkpoint_id) >>> result = yr.get(restored_ins.increment.invoke()) # counter = 2 >>> print(f"Counter after restore: {result}") >>> >>> yr.finalize()