missing attribute in handler shutdown
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in init.py, intorno al codice di shutdown() mostrato nel report, e analizza il comportamento della pulizia dell’handler per l’esempio QTextEditLogger su CPython 3.14. Riproduci il traceback dell’arresto di Windows, quindi verifica che il percorso di pulizia corretto non sollevi più l’eccezione segnalata, preservando al contempo il normale svuotamento e la chiusura dell’handler.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100