`atexit` module breaks refleak check
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Bug description:
If the test registers a callback with atexit module, refleak test will consider it a leak.
def test_refleak(self):
atexit.register(lambda: None)
This is the root cause of the buildbot failure of https://github.com/python/cpython/pull/139185. It's a couple of coincidences that caused the seemingly unrelated issue. Basically, clearing the module cache in test_zipimport made the module-level code in rlcompleter, which includes a register to atexit, run more than once.
There are a few possible approaches to fix this, but I did not find the solution that I'm immediately happy with.
I consider this a test framework bug as this should be a valid behavior. The ideal solution is to keep the atexit callbacks before running test in a loop and restore it after. However, atexit does not provide such an interface, public or private. You can either clear it or run it. The callbacks are stored in a state of the interpreter and we don't have any access to it.
Without that, we either need to somehow calculate the allocated memory by atexit, or hope that no one writes a test that writes to atexit. Of course there might be other ways that I did not think of.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-139305
- gh-139357
- [3.14] gh-139305 was backported as part of gh-139280
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el framework de pruebas refleak y el ejemplo test_refleak que registra un callback de atexit. Inspecciona cómo el borrado de la caché de módulos por parte de test_zipimport hace que el registro a nivel de módulo de rlcompleter se ejecute repetidamente, y revisa los PRs vinculados gh-139305 y gh-139357 para consultar el trabajo existente. Se considera terminado cuando los registros válidos de atexit ya no aparecen como refleaks.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- testing-qa
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 20/100