2019-04-18 00:34:12 -04:00
|
|
|
# test handling of failed heap allocation with dict
|
|
|
|
|
|
|
|
import micropython
|
|
|
|
|
|
|
|
# create dict
|
|
|
|
x = 1
|
|
|
|
micropython.heap_lock()
|
|
|
|
try:
|
2020-03-22 22:26:08 -04:00
|
|
|
{x: x}
|
2019-04-18 00:34:12 -04:00
|
|
|
except MemoryError:
|
2020-03-22 22:26:08 -04:00
|
|
|
print("MemoryError: create dict")
|
2019-04-18 00:34:12 -04:00
|
|
|
micropython.heap_unlock()
|
|
|
|
|
|
|
|
# create dict view
|
2020-03-22 22:26:08 -04:00
|
|
|
x = {1: 1}
|
2019-04-18 00:34:12 -04:00
|
|
|
micropython.heap_lock()
|
|
|
|
try:
|
|
|
|
x.items()
|
|
|
|
except MemoryError:
|
2020-03-22 22:26:08 -04:00
|
|
|
print("MemoryError: dict.items")
|
2019-04-18 00:34:12 -04:00
|
|
|
micropython.heap_unlock()
|