1# Test fairness of scheduler 2 3try: 4 import uasyncio as asyncio 5except ImportError: 6 try: 7 import asyncio 8 except ImportError: 9 print("SKIP") 10 raise SystemExit 11 12 13async def task(id, t): 14 print("task start", id) 15 while True: 16 if t > 0: 17 print("task work", id) 18 await asyncio.sleep(t) 19 20 21async def main(): 22 t1 = asyncio.create_task(task(1, -0.01)) 23 t2 = asyncio.create_task(task(2, 0.1)) 24 t3 = asyncio.create_task(task(3, 0.18)) 25 t4 = asyncio.create_task(task(4, -100)) 26 await asyncio.sleep(0.5) 27 t1.cancel() 28 t2.cancel() 29 t3.cancel() 30 t4.cancel() 31 print("finish") 32 33 34asyncio.run(main()) 35