raising resource warnings prevents resource cleanup

Abierto
#94,900 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
backend

Línea de trabajo

Comienza por Lib/asyncio/unix_events.py en las líneas enlazadas y busca otros lugares donde se emita ResourceWarning antes de la limpieza del recurso. Prueba las rutas de limpieza afectadas con -Werror o filterwarnings=['error', ...]. Se considera terminado cuando la escalada de la advertencia ya no impide que se cierre el recurso subyacente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

stdlib type-bug

Bug report
in a number of places a ResourceWarning is issued before cleaning up a resource eg
https://github.com/python/cpython/blob/944ff8c57c9e8ff5a5bd18925070ddb1504490ab/Lib/asyncio/unix_events.py#L559-L562
normally this is fine - however if you're running with -Werror these warnings are raised as exceptions and so prevent the underlying resource from being cleaned up. This is in particular a problem when running a test suite with filterwarnings=['error', ... where resource cleanup can be delayed for many tests.

I think these should instead be restructured as:

 def __del__(self, _warn=warnings.warn): 
     if self._pipe is not None: 
         msg = f"unclosed transport {self!r}"  # grab the repr before closing the pipe so it displays as "open" still
         self._pipe.close()
         _warn(msg, ResourceWarning, source=self)  # issue the warning after closing the resource

Your environment

  • CPython versions tested on:
  • Operating system and architecture:
Lenguaje dominante
Python
Estrellas
77.2k
Forks
36k
Merge medio
1 d 9 h
PR fusionados (30 d)
558

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python/cpython

Todos los issues de python/cpython

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.