Skip to content

memo

memo #

What the store has for one call key: its sealed results, the steps computing it, or nothing.

Scratch.memo(key) is the one question a memoized call asks, answered in that order:

  1. Results — a hold on every sealed result, in return order. A ragged set, one result of two evicted, is no result at all.
  2. Running — the tree of steps beneath the key's own call: the calls, maps and cg.step blocks in flight, how deep each sits, how long it has run, how far along it is, and the tail of its log.
  3. Nothing — both empty: nobody has computed this key and nobody is.

A key with results reports nothing running: the results are what the caller came for, and the row of a call that has just sealed is on its way out.

Memo dataclass #

What the store has for one call key; see the module for the three answers.

Attributes:

Name Type Description
results tuple[Pinned, ...]

A hold on each sealed result, in return order; empty unless every one of them is present.

running tuple[RunningStep, ...]

The steps in flight beneath the key's call, parents before children and oldest first; empty whenever results is not.

Source code in capturegraph-lib/capturegraph/recipes/scratch/store/memo.py
@dataclass(frozen=True, slots=True)
class Memo:
    """What the store has for one call key; see the module for the three answers.

    Attributes:
        results: A hold on each sealed result, in return order; empty unless
            every one of them is present.
        running: The steps in flight beneath the key's call, parents before
            children and oldest first; empty whenever ``results`` is not.
    """

    results: tuple[Pinned, ...]
    running: tuple[RunningStep, ...]

RunningStep dataclass #

One in-flight step beneath the key asked about.

Attributes:

Name Type Description
id str

The step's identifier.

parent str | None

The step it sits beneath, if any.

label str

What the step is doing, "session_thumbnail" or "Gallery".

identity str | None

The function identity, when the step is a memoized call.

key str | None

The call key as 64 hex characters, when the step is a memoized call.

depth int

0 for the key's own call, one more per level of nesting.

elapsed float

Seconds since the step opened.

done int

How many units are done.

total int | None

How many there are, if known.

note str | None

The step's last message, if any.

fields dict[str, JSONValue]

The named values its notes carried.

log_tail str | None

The last lines of a call's log, if a tool wrote any.

Source code in capturegraph-lib/capturegraph/recipes/scratch/store/memo.py
@dataclass(frozen=True, slots=True)
class RunningStep:
    """One in-flight step beneath the key asked about.

    Attributes:
        id: The step's identifier.
        parent: The step it sits beneath, if any.
        label: What the step is doing, ``"session_thumbnail"`` or ``"Gallery"``.
        identity: The function identity, when the step is a memoized call.
        key: The call key as 64 hex characters, when the step is a memoized call.
        depth: ``0`` for the key's own call, one more per level of nesting.
        elapsed: Seconds since the step opened.
        done: How many units are done.
        total: How many there are, if known.
        note: The step's last message, if any.
        fields: The named values its notes carried.
        log_tail: The last lines of a call's log, if a tool wrote any.
    """

    id: str
    parent: str | None
    label: str
    identity: str | None
    key: str | None
    depth: int
    elapsed: float
    done: int
    total: int | None
    note: str | None
    fields: dict[str, JSONValue]
    log_tail: str | None

call_memo(scratch, key, count) #

What scratch has for key, whose call returns count results.

Source code in capturegraph-lib/capturegraph/recipes/scratch/store/memo.py
def call_memo(scratch: Scratch, key: CallKey, count: int) -> Memo:
    """What ``scratch`` has for ``key``, whose call returns ``count`` results."""
    held = lookup_call(scratch, key, count)
    if held is not None:
        return Memo(tuple(held), ())
    return Memo((), _running_under(scratch, key))