1# Test fairness of cancelling a task
2# That tasks which keeps being cancelled by multiple other tasks gets a chance to run
3
4try:
5    import uasyncio as asyncio
6except ImportError:
7    try:
8        import asyncio
9    except ImportError:
10        print("SKIP")
11        raise SystemExit
12
13
14async def task_a():
15    try:
16        while True:
17            print("sleep a")
18            await asyncio.sleep(0)
19    except asyncio.CancelledError:
20        print("cancelled a")
21
22
23async def task_b(id, other):
24    while other.cancel():
25        print("sleep b", id)
26        await asyncio.sleep(0)
27    print("done b", id)
28
29
30async def main():
31    t = asyncio.create_task(task_a())
32    for i in range(3):
33        asyncio.create_task(task_b(i, t))
34    await t
35
36
37asyncio.run(main())
38