raising resource warnings prevents resource cleanup
还没有人认领这个 Issue。
评估
调研方向
从链接行中的 Lib/asyncio/unix_events.py 开始,查找其他在资源清理之前发出 ResourceWarning 的位置。使用 -Werror 或 filterwarnings=['error', ...] 执行受影响的清理路径。完成标准是警告升级不再阻止底层资源被关闭。
由索引模型根据 Issue 内容生成。
描述
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:
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 558
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
docs pending
难度 2/5 1-3 小时 新手友好度 78/100
-
stdlib type-feature
难度 2/5 1-3 小时 新手友好度 78/100
-
stdlib type-feature
难度 2/5 1-3 小时 新手友好度 72/100
-
build type-bug
难度 2/5 1-3 小时 新手友好度 76/100
-
stdlib topic-email type-feature
难度 2/5 1-3 小时 新手友好度 70/100
相似的 Issue
-
link-check link-check:sphinx-theme
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
难度 2/5 1-3 小时 新手友好度 88/100
OpenHands/extensions#626 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
CSCfi/sd-search-api#39 ·
-
难度 1/5 1 小时以内 新手友好度 90/100