Cloudpickle does not properly register submodule dependencies of a pickled function if the function accesses the submodule via `getattr` (or equivalent means)
还没有人认领这个 Issue。
评估
调研方向
从 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 小时
- 30 天内合并 PR
- 1
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 一周以上 新手友好度 35/100
cloudpipe/cloudpickle#589 ·
-
难度 5/5 一周以上 新手友好度 20/100
cloudpipe/cloudpickle#587 ·
查看 cloudpipe/cloudpickle 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
spec-kitty/spec-kitty#5319 ·
维护者通常 1 天内回复
-
backend::vllm diffusion multimodal
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
openai/openai-agents-python#5229 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复