python / python/cpython

[3.14] change in behaviour in gc.get_referrers(some_local)

Aberta
#125,603 2 comentários 0 reações 1 responsável Ver no GitHub

@markshannon já está trabalhando nisso.

Desde 16/10/2024.

3.14 triaged type-bug
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

Bug report

Bug description:
import gc

async def demo():
    class A:
        pass

    a = A()
    print(gc.get_referrers(a))


try:
    demo().send(None)
except StopIteration as e:
    print(f"{e.value=}")

on 3.11-3.13 this prints:

[]
e.value=None

on 3.14 this prints:

[<coroutine object demo at 0x7d00fff85000>]
e.value=None

this makes gc.get_referrers less useful in detecting cyclic garbage where I'd like to be able to make the assertion that the current frame is the only referrer to an Exception.

the alternative is to hold a weak reference to the object, delete the object and see if the weak reference is dead with the gc disabled. But then I don't get any debug information in my failing test of why the object is still alive.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Linux

note: @markshannon asked me to open this issue

Linked PRs
  • gh-125640

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.