Suspend & Resume
What feed_start (and each resume / resume_auto) yields — a completed run, or a suspension to answer — and the
ExternalResult shapes those answers take.
See snapshots for the concepts.
The result of a completed feed_start execution.
The final value, converted to a Python object on each access.
Type: Any
A paused execution waiting for an external function or OS call result.
For OS calls is_os_function is True and function_name is the
OsFunction name; resume with a value, an exception, or
resume_not_handled().
Session uuid of the routed receiver — a host class instance sent
via ClassInstance, or a host class sent via ClassType (a
classmethod call, or construction, which arrives as __call__);
None for plain external functions and OS calls. The receiver is not
included in args.
def resume(result: ExternalResult) -> SyncSnapshot
Resume with the call’s result; resumes at most once.
Answers only this call: the result is passed straight through, and
neither the feed’s mounts nor the captured os= are consulted. Use
resume_auto() for those.
def resume_not_handled() -> SyncSnapshot
Resume an OS-call snapshot with monty’s default unhandled behaviour.
def resume_auto() -> SyncSnapshot
Answer this call automatically, then return the next snapshot (or
MontyComplete). Resumes at most once.
An OS call is offered to the feed’s mounts first, falling back to the
os= captured at feed_start / load_snapshot and then to monty’s
unhandled default. An external call is resolved through
external_lookup=; a name absent from it makes the sandbox raise
NameError (as in feed_run). A coroutine external raises
RuntimeError — use AsyncMonty for async externals.
def dump() -> bytes
Serialize the suspended worker; restore via MontySession.load_snapshot.
A paused execution waiting for the value of an undefined name, or —
when object_id is set — a lazy attribute lookup on a host-backed object
(a ClassInstance instance, or a ClassType class).
Session uuid of the receiver for a lazy attribute lookup; None
for a plain undefined-name lookup. An omitted-value resume raises
AttributeError (not NameError) for attribute lookups.
def resume(*, value: Any = ...) -> SyncSnapshot
Resume by binding the name to value (any value, including None), or
omit value to leave the name undefined — the sandbox then raises
NameError, or AttributeError when object_id is set (a lazy
attribute lookup on a host-backed object).
def resume_auto() -> SyncSnapshot
Answer this name lookup automatically, then return the next snapshot
(or MontyComplete). A plain lookup resolves from the captured
external_lookup= (an absent name raises NameError in the sandbox);
an object_id lookup resolves through the sending wrapper’s
lazy_attrs policy (a denied or absent attribute raises
AttributeError; any other exception raised while serving it, or a
value that cannot be converted, is raised inside the sandbox).
def dump() -> bytes
Serialize the suspended worker; restore via MontySession.load_snapshot.
A paused execution where every sandbox task is blocked on external futures.
def resume(results: dict[int, ExternalSettledResult]) -> SyncSnapshot
Resume with settled results for one or more pending futures (by
call_id); a future cannot resolve to another future.
def resume_auto() -> NoReturn
Always raises RuntimeError: a sync session cannot drive coroutine
externals. Resolve the pending futures manually with resume({...}), or
use AsyncMonty. Does not consume the snapshot.
def dump() -> bytes
Serialize the suspended worker; restore via MontySession.load_snapshot.
Async sibling of FunctionSnapshot; resume/resume_not_handled are awaitable.
As FunctionSnapshot.object_id: the routed receiver’s session uuid.
@async
def resume_auto() -> AsyncSnapshot
Async sibling of FunctionSnapshot.resume_auto. A coroutine external
is spawned and answered with a pending future, so other sandbox tasks
keep running; it is later settled by AsyncFutureSnapshot.resume_auto.
Async sibling of NameLookupSnapshot.
As NameLookupSnapshot.object_id: the host object a lazy attribute is read from.
@async
def resume_auto() -> AsyncSnapshot
Async sibling of NameLookupSnapshot.resume_auto.
Async sibling of FutureSnapshot.
@async
def resume_auto() -> AsyncSnapshot
Wait for one or more coroutine externals spawned by earlier
resume_auto calls to settle, deliver them, and return the next
snapshot. Raises if there are no pending coroutines to await (e.g. a
snapshot restored via load_snapshot).
Bases: TypedDict
Represents the return value of an external function call.
Bases: TypedDict
Represents an exception raised during an external function call.
Bases: TypedDict
Represents an exception raised during an external function call by its type and optional message.
Prefer this variant over ExternalException when the caller does not have
(or does not want to construct) a concrete Python exception instance —
e.g. when resuming a snapshot whose original exception type is not
available, or when resuming from another language.
Bases: TypedDict
Represents a pending future returned from an external function call.
What MontySession.feed_start (and each sync resume / resume_auto) yields.
Type: TypeAlias Default: FunctionSnapshot | NameLookupSnapshot | FutureSnapshot | MontyComplete
What AsyncMontySession.feed_start (and each async resume / resume_auto) yields.
Type: TypeAlias Default: AsyncFunctionSnapshot | AsyncNameLookupSnapshot | AsyncFutureSnapshot | MontyComplete
A caller’s answer to a FunctionSnapshot: a return value, an exception (by
instance or by type name), or a pending future.
Default: ExternalSettledResult | ExternalFuture
A settled answer — a return value or an exception, but never a pending
future. Resolving a FutureSnapshot requires settled results: a future
cannot resolve to another future.
Default: ExternalReturnValue | ExternalException | ExternalExceptionData