Cancel and await the task you own
Cancellation is a request delivered at an await point. Calling cancel without awaiting the task leaves cleanup and exceptions unresolved. A parent that owns a task should request cancellation, await completion and suppress only the expected CancelledError.
The coroutine may already have finished successfully or failed before cancellation. Those outcomes must retain their meaning. Catching every exception would hide a broken worker. The tests synchronize through an Event so they verify the actual cleanup path without sleeps that depend on device speed.
import asyncio
async def main():
task=asyncio.create_task(asyncio.sleep(1))
task.cancel()
try: await task
except asyncio.CancelledError:
print("cancelled")
asyncio.run(main())Review the design
Awaiting establishes the cleanup boundary. A task can refuse cancellation, so production owners also need a shutdown policy for uncooperative work; this contract assumes cooperative coroutines.
Your task
Implement async stop_owned(task). Cancel and await it; return None for cancellation or its successful result. Propagate other failures.
The explanation opens here once every check passes.