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.
  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, as a step named after the function, then seal what the body returned.

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/recipes/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 _results(returns, memo.results)
    with scratch.lock_call(key):
        memo = scratch.memo(key, count)
        if memo.results:
            return _results(returns, memo.results)
        sealed = _compute(scratch, key, identity, label, returns, body)
    return _results(returns, sealed)