1import gc 2import weakref 3 4foo_dict = weakref.WeakValueDictionary() 5 6cdef class Foo: 7 cdef object __weakref__ 8 9def test_weakref(key): 10 """ 11 Test af9cfeb5f94d9cd4f2989fc8e111c33208494ba4 fix. 12 Originally running it using debug build of python lead to:: 13 14 visit_decref: Assertion `gc->gc.gc_refs != 0' failed 15 16 >>> _ = gc.collect() 17 >>> _ = test_weakref(48) 18 >>> _ = gc.collect() 19 """ 20 obj = Foo() 21 foo_dict[key] = obj 22 return obj 23 24