missing attribute in handler shutdown
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从报告中所示的shutdown()代码附近的__init__.py开始,检查在CPython 3.14上QTextEditLogger示例的处理器清理行为。重现Windows关机时的traceback,然后验证修正后的清理路径不再引发所报告的异常,同时保持处理器正常的刷新和关闭。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100