python / python/cpython

Max recursion during unpickling with a proxy object

オープン
#133,015 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

extension-modules pending stdlib type-bug
主要言語
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、Python 3.11 で提供された FooWrapper と multiprocessing.Queue の再現コードを実行し、続いて queue.get() のアンピックリング経路と wrapper の getattr を追跡します。ラップされたオブジェクトが復元される前に、なぜ属性アクセスが再帰するのかを特定します。Foo.var を引き続き公開しつつ、wrapper を RecursionError なしでキューに入れて取得でき、再現コードに対するリグレッションカバレッジがあることを完了条件とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。