Skip to content

run

run #

run_call — one memoized call, in three steps.

  1. Ask the scratch for the key's memo (the three answers); results are served, with one log line saying the call was cached.
  2. On nothing, claim the key under its per-call lock and ask again: of any number of callers arriving together exactly one gets past this point, the rest block until it seals and then hit.
  3. Compute in a fresh workspace, under a log scope named after the function, then seal what the body returned; a file already in the scratch is stored as a hard link, since nothing there is written in place. A Missing result (any position, for a tuple) is not a result to seal: the workspace is released, one line is logged and Missing is returned, so the next call runs the body again.

run_call(key, identity, label, returns, body) #

The results of the call key: served from the scratch, or computed and sealed.

Parameters:

Name Type Description Default
key CallKey

The call's cache key.

required
identity str

The function's cache identity, under which the call reports itself.

required
label str

The function's name, which the call's step shows.

required
returns ReturnSpec

The declared return type(s).

required
body Callable[[], object]

The undecorated call, run only when nothing is sealed for key.

required
Source code in capturegraph-lib/capturegraph/scratch/calls/run.py
def run_call(
    key: CallKey,
    identity: str,
    label: str,
    returns: ReturnSpec,
    body: Callable[[], object],
) -> object:
    """The results of the call ``key``: served from the scratch, or computed and sealed.

    Args:
        key: The call's cache key.
        identity: The function's cache identity, under which the call reports itself.
        label: The function's name, which the call's step shows.
        returns: The declared return type(s).
        body: The undecorated call, run only when nothing is sealed for ``key``.
    """
    scratch = active_scratch()
    count = len(return_types(returns))

    memo = scratch.memo(key, count)
    if memo.results:
        return _served(label, returns, memo.results)
    with scratch.lock_call(key):
        memo = scratch.memo(key, count)
        if memo.results:
            return _served(label, returns, memo.results)
        sealed = _compute(scratch, key, identity, label, returns, body)
    if isinstance(sealed, _Missing):
        return sealed
    return _results(returns, sealed)