Max recursion during unpickling with a proxy object
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- 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