Max recursion during unpickling with a proxy object
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece executando o reprodutor fornecido de FooWrapper e multiprocessing.Queue no Python 3.11 e, em seguida, rastreie o caminho de descompactação de queue.get() e o getattr do wrapper. Identifique por que o acesso ao atributo entra em recursão antes que o objeto encapsulado seja restaurado. Considera-se concluído quando o wrapper puder ser colocado na fila e recuperado sem RecursionError, continuando a expor Foo.var, com cobertura de regressão para o reprodutor.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- operating-systems
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100