Why can I skip calling log_func in yield log_func
, i.e. I can just write yield
and the code still works. Why is that? How does yield
work in this case?
import time
from contextlib import contextmanager
@contextmanager
def log_exec(log_func):
s = time.perf_counter()
yield log_func
e = time.perf_counter()
log_func(e - s)
with log_exec(log.debug):
time.sleep(1)