summaryrefslogtreecommitdiff
path: root/t/task_groups_and_cancel.py
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-07-19 22:21:10 -0600
committerbd <bdunahu@operationnull.com>2025-07-19 22:21:10 -0600
commitac55d9ff0b588b91202ccad72ee71e508e33ad08 (patch)
tree4933b49b67f1affa16f8e7c63e0d214bfa7d62e8 /t/task_groups_and_cancel.py
parentd08f067f8f470b440b563293397116d6036c4d71 (diff)
Reformat repository to allow for new unit tests
Diffstat (limited to 't/task_groups_and_cancel.py')
-rw-r--r--t/task_groups_and_cancel.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/t/task_groups_and_cancel.py b/t/task_groups_and_cancel.py
new file mode 100644
index 0000000..dcc6bbe
--- /dev/null
+++ b/t/task_groups_and_cancel.py
@@ -0,0 +1,35 @@
+import asyncio
+
+
+async def sleep():
+ await asyncio.sleep(3)
+ print('I should never finish!')
+ return 0
+
+
+async def work():
+ i = 0
+ while i < 50:
+ i += 1
+ await asyncio.sleep(0.2)
+ return 0
+
+
+async def explode():
+ await asyncio.sleep(1.5)
+ a = 1 / 0
+ return a
+
+
+async def main():
+ # exploding will bring all other tasks down with it!
+ try:
+ async with asyncio.TaskGroup() as tg:
+ tg.create_task(sleep())
+ tg.create_task(work())
+ tg.create_task(explode())
+ except:
+ pass
+
+
+asyncio.run(main())