sys.monitoring `PY_YIELD` leaks internal `async_generator_wrapped_value` object
未关闭
还没有人认领这个 Issue。
interpreter-core
type-feature
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Rather than the actual value, sys.monitoring's PY_YIELD event passes in to the callback the internal async_generator_wrapped_value.
I imagine this is a bug... it's inconsistent with what it does for non-async generators.
import sys
import types
import typing
import asyncio
async def gen():
yield 42
async def main():
async for _ in gen():
pass
def handle_yield(code: types.CodeType, offset: int, value: object) -> typing.Any:
if code.co_filename == __file__:
print(f"yield name={code.co_qualname} {type(value)=}")
sysmon = sys.monitoring
sysmon.use_tool_id(4, "r")
sysmon.register_callback(4, sysmon.events.PY_YIELD, handle_yield)
sysmon.set_events(4, sysmon.events.PY_YIELD)
asyncio.run(main())
This prints out:
yield name=gen type(value)=<class 'async_generator_wrapped_value'>
CPython versions tested on:
3.12, 3.13, 3.14
Operating systems tested on:
macOS, Linux
Linked PRs
- gh-129031
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,在受影响的 CPython 版本上运行提供的 sys.monitoring PY_YIELD 复现,并检查 callback 对 async generators 的行为。查看链接的 PR gh-129031,了解当前的实现方向;当 callback 接收到 yielded value 而不是内部的 async_generator_wrapped_value 对象,并且对此情况有覆盖时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100