#!/usr/bin/env python3 from asyncio import CancelledError, ensure_future, sleep, get_event_loop async def main(): wait = ensure_future(sleep(10)) w2 = await sleep(1) wait.cancel() if not wait.done(): print("wait is still running.") if not wait.cancelled(): print("wait is not set to cancelled!") try: await wait except CancelledError: print("Awaiting cancelled future produced a CancelledError") else: print("Awaiting was successful!") if not wait.done(): print("wait is still running!?") get_event_loop().run_until_complete(main())