# Breakpoint 1, _siftup (heap=0x4056b344, pos=65534) at /home/p/Python-3.4.1/Modules/_heapqmodule.c:121 # warning: Source file is more recent than executable. # 121 Py_DECREF(PyList_GET_ITEM(heap, pos)); # (gdb) print *heap->ob_item[pos] # $1 = {_ob_next = 0x41812058, _ob_prev = 0x831159c , ob_refcnt = 1, ob_type = 0x4058fd1c} # (gdb) n # 122 PyList_SET_ITEM(heap, pos, newitem); # (gdb) print *heap->ob_item[pos] # Cannot access memory at address 0x3fff8 # (gdb) print *heap # $2 = {ob_base = {ob_base = {_ob_next = 0x4059c0b4, _ob_prev = 0x405903b4, ob_refcnt = 2, ob_type = 0x830e1c0 }, # ob_size = 0}, ob_item = 0x0, allocated = 0} # (gdb) n # # Program received signal SIGSEGV, Segmentation fault. # 0x4002f150 in _siftup (heap=0x4056b344, pos=65534) at /home/p/Python-3.4.1/Modules/_heapqmodule.c:122 # 122 PyList_SET_ITEM(heap, pos, newitem); import heapq as h import math N = 112233 logN = int(math.log(N)/math.log(2)) childpos = (2**logN)-2 pos = int((childpos-1)/2) g_cnt = 0 class X(): def __init__(self, i): self.i = i def __lt__(self, o): global L, g_cnt g_cnt += 1 print("cnt:", g_cnt, "pos:", (self.i-1)/2) if g_cnt == logN-1: L[pos] = Y() return 0 class Y(): def __del__(self): global L print("__del__ Y") L[childpos] = Z() class Z(): def __del__(self): global L, gZ print("__del__ Z") gZ = L[childpos] L[:] = [] L = [X(i) for i in range(N)] h.heappop(L)