From cc07a631f1efeff7bf63b6e8dcadb4a187c598e4 Mon Sep 17 00:00:00 2001 From: pro100ton Date: Sun, 17 Nov 2024 23:18:06 +0300 Subject: [PATCH] Add 6.9 theory --- 6_tasks/6_9_cancelation.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 6_tasks/6_9_cancelation.py diff --git a/6_tasks/6_9_cancelation.py b/6_tasks/6_9_cancelation.py new file mode 100644 index 0000000..a03a104 --- /dev/null +++ b/6_tasks/6_9_cancelation.py @@ -0,0 +1,23 @@ +import asyncio + + +async def cancel_test(): + try: + await asyncio.sleep(5) + except asyncio.CancelledError: + print("Printing after cancel") + finally: + return 5 + + + +async def main(): + task = asyncio.create_task(cancel_test()) + await asyncio.sleep(0.1) + print(task.cancelling()) + await asyncio.sleep(0.1) + print(task.cancelled()) + print(task.result()) + return task + +asyncio.run(main())