what does yield without value do in context manager
问题 import contextlib import time @contextlib.contextmanager def time_print(task_name): t = time.time() try: yield finally: print task_name, "took", time.time() - t, "seconds." def doproc(): x=1+1 with time_print("processes"): [doproc() for _ in range(500)] # processes took 15.236166954 seconds. when does doproc get executed when using this decorator? 回答1: yield expression returns control to the whatever is using the generator. The generator pauses at this point, which means that the