python / python/cpython

missing attribute in handler shutdown

Abierto
#153,812 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

pending
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:

My code uses the logging handler package (https://docs.python.org/3/library/logging.handlers.html). On closing, I was getting

Exception ignored in atexit callback <function shutdown at 0x0000017934F72770>:
Traceback (most recent call last):
File "...._init_.py", line 2244, in shutdown
if getattr(h, 'flushOnClose', True):
RuntimeError: wrapped C/C++ object of type QTextEditLogger has been deleted

'QTextEditLogger' being a child class of Handler:

class QTextEditLogger(Handler, QObject):
    appendPlainText = pyqtSignal(str)

    def __init__(self, parent):
        Handler.__init__(self) 
        QObject.__init__(self)
        ....

when the program closed.
I finally traced the problem back to the shutdown() function in the getLogger class.

       if h:
           try:
              h.acquire()
              # MemoryHandlers might not want to be flushed on close,
              # but circular imports prevent us scoping this to just
              # those handlers.  hence the default to True.
              if getattr(h, 'flushOnClose', True):
                  h.flush()
              h.close()

Not all handlers have the 'flushOnClose' attribute! So it throws an exception, as per the documentation, BTW, when getattr() is called and 'flushOnClose' isn't there.

The fix is simple, I added the hasattr() function to see if the attribute exists:

       **if hasattr(h, 'flushOnClose'):**                     
             if getattr(h, 'flushOnClose', True):
                h.flush()
        h.close()

CPython versions tested on:

3.14

Operating systems tested on:

Windows

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.

Línea de trabajo

Comienza en init.py, alrededor del código de shutdown() mostrado en el informe, e inspecciona cómo funciona la limpieza del controlador para el ejemplo de QTextEditLogger en CPython 3.14. Reproduce el traceback del cierre en Windows y, a continuación, verifica que la ruta de limpieza corregida ya no genere la excepción indicada, al tiempo que mantiene el vaciado y el cierre normales del controlador.

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

Evaluación

Stack tecnológico
python
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
52/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.