Max recursion during unpickling with a proxy object
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy trình tái hiện được cung cấp cho FooWrapper và multiprocessing.Queue trên Python 3.11, sau đó lần theo đường dẫn unpickle của queue.get() và getattr của wrapper. Xác định lý do việc truy cập thuộc tính bị đệ quy trước khi đối tượng được bọc được khôi phục. Được xem là hoàn tất khi wrapper có thể được đưa vào queue và lấy ra mà không xảy ra RecursionError, đồng thời vẫn expose Foo.var, với kiểm thử hồi quy cho trình tái hiện.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- operating-systems
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100