1# check that heap_lock/heap_unlock work as expected 2 3import micropython 4 5l = [] 6l2 = list(range(100)) 7 8micropython.heap_lock() 9micropython.heap_lock() 10 11# general allocation on the heap 12try: 13 print([]) 14except MemoryError: 15 print("MemoryError") 16 17# expansion of a heap block 18try: 19 l.extend(l2) 20except MemoryError: 21 print("MemoryError") 22 23print(micropython.heap_unlock()) 24 25# Should still fail 26try: 27 print([]) 28except MemoryError: 29 print("MemoryError") 30 31micropython.heap_unlock() 32 33# check that allocation works after an unlock 34print([]) 35