Skip to content

Max recursion during unpickling with a proxy object #133015

Open
@gbrawn

Description

@gbrawn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirpendingThe issue will be closed if no feedback is providedstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions