missing attribute in handler shutdown
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in init.py beim im Report gezeigten shutdown()-Code und untersuche, wie die Bereinigung des Handlers für das QTextEditLogger-Beispiel unter CPython 3.14 funktioniert. Reproduziere den Windows-Shutdown-Traceback und verifiziere anschließend, dass der korrigierte Bereinigungspfad die gemeldete Ausnahme nicht mehr auslöst und dabei das normale Leeren und Schließen des Handlers beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 52/100