From ab12d7efc02916ccc46d81d5fdfc3991e9d1412c Mon Sep 17 00:00:00 2001 From: pro100ton Date: Thu, 14 Nov 2024 22:03:23 +0300 Subject: [PATCH] Add 6.5 section task --- 6_tasks/6_5_03_task.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 6_tasks/6_5_03_task.py diff --git a/6_tasks/6_5_03_task.py b/6_tasks/6_5_03_task.py new file mode 100644 index 0000000..b4b63cd --- /dev/null +++ b/6_tasks/6_5_03_task.py @@ -0,0 +1,16 @@ +import asyncio + + +async def process_task(): + await asyncio.sleep(1) + cur_task = asyncio.current_task() + return id(cur_task) + + +async def main(): + tasks = [asyncio.create_task(process_task()) for _ in range(0, 10)] + done, tasks = await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED) + return [task_res.result() for task_res in done] + + +asyncio.run(main())