[Python] Fatal Python error: GC object already tracked when invoking set constructor

Discussão em 'Python' iniciado por Stack, Março 1, 2025.

  1. Stack

    Stack Membro Participativo

    I have following Python2 function in a big Python-Cython project (print statements added for debugging):

    import gc
    def e_closure (startstate):
    """Return all states reachable from startstates on epsilon transitions.
    """
    print('eclos1', startstate)
    print(len(gc.get_objects()))
    sys.stdout.flush()
    work = [startstate]
    set()
    print('eclos2')
    print(len(gc.get_objects()))
    sys.stdout.flush()
    result = set()
    print('eclos3')
    sys.stdout.flush()
    while work:
    s = work.pop()
    result.add(s)
    for n in s.get_transitions(state.EPSILON):
    if n not in result:
    work.append(n)
    x = sorted(result, key=lambda s: s.name)
    return x


    This is crashing with error Fatal Python error: GC object already tracked when set() constructor is called. That too not first invocation, but instead exactly on 10th invocation. If I add additional set() call in previous lines, it crashes there. But it is not crashing if I add dict() or list() calls instead.

    Sample logs:

    ('eclos1', start)
    6961
    eclos2
    6962
    eclos3
    ('eclos1', d0)
    6962
    eclos2
    6963
    eclos3
    ('eclos1', d2)
    6963
    eclos2
    6964
    eclos3
    ('eclos1', d3)
    6964
    eclos2
    6965
    eclos3
    ('eclos1', d4)
    6965
    eclos2
    6966
    eclos3
    ('eclos1', d1)
    6966
    eclos2
    6967
    eclos3
    ('eclos1', c0)
    6967
    eclos2
    6968
    eclos3
    ('eclos1', c2)
    6968
    eclos2
    6969
    eclos3
    ('eclos1', c3)
    6969
    eclos2
    6970
    eclos3
    ('eclos1', c4)
    6970


    In this entire function, only get_transitions is a cython function. Also, it was working before and causing issues only after cythonization. But I'm unable to understand what is the issue and how to debug it.

    Python: Python 2.7.12 Cython: Cython version 0.23.4

    Continue reading...

Compartilhe esta Página