1# Test fairness of Event.set() 2# That tasks which continuously wait on events don't take over the scheduler 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 task1(id): 15 for i in range(4): 16 print("sleep", id) 17 await asyncio.sleep(0) 18 19 20async def task2(id, ev): 21 for i in range(4): 22 ev.set() 23 ev.clear() 24 print("wait", id) 25 await ev.wait() 26 27 28async def main(): 29 ev = asyncio.Event() 30 tasks = [ 31 asyncio.create_task(task1(0)), 32 asyncio.create_task(task2(2, ev)), 33 asyncio.create_task(task1(1)), 34 asyncio.create_task(task2(3, ev)), 35 ] 36 await tasks[1] 37 ev.set() 38 39 40asyncio.run(main()) 41