1# test that basic scheduling of tasks, and uasyncio.sleep_ms, does not use the heap
2
3import micropython
4
5# strict stackless builds can't call functions without allocating a frame on the heap
6try:
7    f = lambda: 0
8    micropython.heap_lock()
9    f()
10    micropython.heap_unlock()
11except RuntimeError:
12    print("SKIP")
13    raise SystemExit
14
15try:
16    import uasyncio as asyncio
17except ImportError:
18    try:
19        import asyncio
20    except ImportError:
21        print("SKIP")
22        raise SystemExit
23
24
25async def task(id, n, t):
26    for i in range(n):
27        print(id, i)
28        await asyncio.sleep_ms(t)
29
30
31async def main():
32    t1 = asyncio.create_task(task(1, 4, 10))
33    t2 = asyncio.create_task(task(2, 4, 25))
34
35    micropython.heap_lock()
36
37    print("start")
38    await asyncio.sleep_ms(1)
39    print("sleep")
40    await asyncio.sleep_ms(100)
41    print("finish")
42
43    micropython.heap_unlock()
44
45
46asyncio.run(main())
47