mirror of
https://github.com/micropython/micropython.git
synced 2026-05-01 13:20:14 +02:00
2cca3481f2
Needs a native exp file because native code doesn't print line numbers in the traceback. Signed-off-by: Damien George <damien@micropython.org>
43 lines
807 B
Python
43 lines
807 B
Python
# Test weakref ref/finalize raising an exception within the callback.
|
|
#
|
|
# This test has different output to CPython due to the way that MicroPython
|
|
# prints the exception.
|
|
|
|
try:
|
|
import weakref
|
|
except ImportError:
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
import gc
|
|
|
|
|
|
class A:
|
|
def __str__(self):
|
|
return "<A object>"
|
|
|
|
|
|
def callback(*args):
|
|
raise ValueError("weakref callback", args)
|
|
|
|
|
|
def test():
|
|
print("test ref with exception in the callback")
|
|
a = A()
|
|
r = weakref.ref(a, callback)
|
|
a = None
|
|
clean_the_stack = [0, 0, 0, 0]
|
|
gc.collect()
|
|
print("collect done")
|
|
|
|
print("test finalize with exception in the callback")
|
|
a = A()
|
|
weakref.finalize(a, callback)
|
|
a = None
|
|
clean_the_stack = [0, 0, 0, 0]
|
|
gc.collect()
|
|
print("collect done")
|
|
|
|
|
|
test()
|