Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardPythonawait schedulingSingle-choice MCQ

Inside a running loop, a coroutine does `r = await fut` on a not-yet-done `Future`. When `fut.set_result(...)` is later called, how does the awaiting Task get resumed?

async def main(): loop = asyncio.get_running_loop() fut = loop.create_future() log = [] fut.add_done_callback(lambda f: log.append('cb')) fut.set_result(1) log.append('after set') await asyncio.sleep(0) print(log)