@contextmanager
def deferral():
    deferred = []
    defer = lambda f, *a, **k: deferred.append((f, a, k))
    try:
        yield defer
    finally:
        while deferred:
            f, a, k = deferred.pop()
            f(*a, **k)


#: Alias of :func:`_thread.get_ident`.
Defers a function call when it is being required like Go.
dataset/ETHPy150Open what-studio/profiling/profiling/utils.py/deferral