Max recursion during unpickling with a proxy object
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Description of Problem
A wrapper class was needed to wrap an underlying object while exposing the underlying object's attributes. https://stackoverflow.com/questions/68926132/creation-of-a-class-wrapper-in-python
When creating a wrapper object for an object to be placed on a multiprocessing queue, if the wrapper object overrides the getattr method, and the object is retrieved from the queue, a max recursion depth error is observed. The expected behavior was for the wrapper object to be returned and have the underlying object exposed in the process that was handling the object.
Example Snippet
from multiprocessing import Queue
class Foo:
"""
Any old object
"""
def __init__(self, var: int):
self._var = var
@property
def var(self) -> int:
return self._var
class FooWrapper:
"""
Wrapper class to expose underlying object attrs
"""
def __init__(self, foo: Foo):
self.foo = foo
def __getattr__(self, name):
return getattr(self.foo, name)
if __name__=="__main__":
queue = Queue()
foo = Foo(2)
foo_wrapper = FooWrapper(foo)
queue.put(foo_wrapper)
message_wrapper = queue.get() # This fails due to max recursion depth reached
>>
return getattr(self.foo, name)
^^^^^^^^
[Previous line repeated 994 more times]
RecursionError: maximum recursion depth exceeded
CPython versions tested on:
3.11
Operating systems tested on:
Linux, Windows
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 Python 3.11 上运行提供的 FooWrapper 和 multiprocessing.Queue 复现程序,然后跟踪 queue.get() 的反序列化路径以及 wrapper 的 getattr。确定为什么在被包装对象恢复之前,属性访问会发生递归。完成标准是:wrapper 可以放入队列并取出而不会出现 RecursionError,同时仍然能够暴露 Foo.var,并为该复现程序提供回归测试覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100