FunctionSnapshot
Represents a paused execution waiting for an external function call return value. Contains information about the pending external function call and allows resuming execution with the return value.Properties
The name of the script being executed
Whether this snapshot is for an OS function call (e.g.,
Path.stat)Whether this snapshot is for a dataclass method call (first arg is
self)The name of the function being called (external function or OS function like
'Path.stat'). Will be an OsFunction if is_os_function is True.The positional arguments passed to the external function
The keyword arguments passed to the external function
The unique identifier for this external function call
Methods
resume()
resume() may only be called once on each FunctionSnapshot instance. The GIL is released allowing parallel execution.
The value to return from the external function call
An exception to raise in the Monty interpreter
A future to await in the Monty interpreter. Pass
... (ellipsis) to indicate a pending future.FunctionSnapshotif another external function call is pendingNameLookupSnapshotif another name lookup is pendingFutureSnapshotif futures need to be resolvedMontyCompleteif execution finished
TypeError: If both arguments are provided or if invalid arguments are passedRuntimeError: If execution has already completed or if resume was already calledMontyRuntimeError: If the code raises an exception during execution
dump()
Bytes containing the serialized FunctionSnapshot instance
print_callback is not serialized and must be re-provided via set_print_callback() after loading if print output is needed.
Raises:
ValueError: If serialization failsRuntimeError: If the progress has already been resumed
load() (static method)
The serialized FunctionSnapshot data from
dump()Optional callback for print output
Optional list of dataclass types to register for proper
isinstance() support on outputA new FunctionSnapshot instance
ValueError: If deserialization fails
Example
MontyComplete
The result of a completed code execution.Properties
The final output value from the executed code
Example
NameLookupSnapshot
Represents a paused execution waiting for a name lookup to be resolved. This is used in advanced scenarios where variable lookups need external resolution.Properties
The name of the script being executed
The name of the variable being looked up
Methods
resume()
value is passed, a NameError is raised. resume() may only be called once on each NameLookupSnapshot instance. The GIL is released allowing parallel execution.
The value from the name lookup, if any
FunctionSnapshotif an external function call is pendingNameLookupSnapshotif more futures need to be resolvedFutureSnapshotif another name lookup is pendingMontyCompleteif execution finished
TypeError: If result dict has invalid keysRuntimeError: If execution has already completedMontyRuntimeError: If the code raises an exception during execution
dump() and load()
Similar toFunctionSnapshot, NameLookupSnapshot also supports serialization:
FutureSnapshot
Represents a paused execution waiting for multiple futures to be resolved. This is used when handling async operations or parallel external function calls.Properties
The name of the script being executed
The call IDs of the pending futures. Raises an error if the snapshot has already been resumed.
Methods
resume()
resume() may only be called once on each FutureSnapshot instance. The GIL is released allowing parallel execution.
Dict mapping
call_id to result dict. Each result dict must have either 'return_value' or 'exception' key (not both).FunctionSnapshotif an external function call is pendingNameLookupSnapshotif more futures need to be resolvedFutureSnapshotif more futures need to be resolvedMontyCompleteif execution finished
TypeError: If result dict has invalid keysRuntimeError: If execution has already completedMontyRuntimeError: If the code raises an exception during execution
dump() and load()
Similar toFunctionSnapshot, FutureSnapshot also supports serialization:
ExternalResult Type
TheExternalResult type is used when resuming FutureSnapshot instances. Itβs a union type:
Example with FutureSnapshot
Serialization Example
Related
- Monty class - Main class that creates snapshots via
start() - Errors - Error types that can be raised during execution
