Cloudpickle does not properly register submodule dependencies of a pickled function if the function accesses the submodule via `getattr` (or equivalent means)
まだ誰も着手していません。
評価
調査の方向性
cloudpickle/cloudpickle.py の 383 行付近にあるサブモジュール検出ロジックから始め、次に報告にある getattr または vars(concurrent)['futures'] の例で問題を再現してください。pickling 中に名前がどのように収集されるかを追跡し、サブモジュール名に間接的にアクセスした場合に、dump された関数を別のセッションでロードして正常に呼び出せることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
As seen on master:
>>> import cloudpickle
>>> cloudpickle.version
'3.2.0.dev0'
>>> import concurrent.futures
>>> def func():
... x = getattr(concurrent, 'futures').ThreadPoolExecutor
...
>>> func() # can be succesfully called
>>> cloudpickle.dump(func, open('/tmp/dump', 'wb'))
Then in another session:
>>> import cloudpickle
>>> cloudpickle.load(open('/tmp/dump', 'rb'))() # not callable upon load
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in func
AttributeError: module 'concurrent' has no attribute 'futures'
The reason is that at pickle time, the submodule detection logic only registers that a function needs a submodule x.y.z if the strings y, z all appear in the set of names stored in the function's code object. If the pickled function were to access the submodule via concurrent.futures, then both concurrent and futures appear in the set of names. But in the failing example above, 'futures' is a string and so doesn't appear in the set of names.
We can trigger the failure by replacing the getattr call with say vars(concurrent)['futures'] or concurrent.__dict__['futures'] for the same reason.
Relates to this issue about slow performance when pickling functions that use packages.
One could argue that this access pattern is sufficiently abnormal that cloudpickle doesn't need to handle it properly. But in the related issue, a maintainer asked me to make a new issue for this problem.
- 主要言語
- Python
- スター
- 1.9k
- フォーク
- 197
- 平均マージ
- 1日 10時間
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudpipe/cloudpickle のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudpipe/cloudpickle#593 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
cloudpipe/cloudpickle#595 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
cloudpipe/cloudpickle#592 · コメント 2 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
cloudpipe/cloudpickle#589 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
cloudpipe/cloudpickle#587 ·
cloudpipe/cloudpickle の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
PedestrianDynamics/pyFDS-Evac#199 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
521xueweihan/HelloGitHub#3790 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
sandialabs/atlas-ui-3#978 ·
メンテナーはふだん 1 日以内に返信
-
area: tests perceived difficulty: 2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Nitjsefnie-Harness-Commons/daedalus#1255 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
EleutherAI/lm-evaluation-harness#4256 ·
メンテナーはふだん 1 日以内に返信