Cloudpickle does not properly register submodule dependencies of a pickled function if the function accesses the submodule via `getattr` (or equivalent means)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Bắt đầu từ logic phát hiện submodule trong cloudpickle/cloudpickle.py, khoảng dòng 383, sau đó tái hiện vấn đề với các ví dụ getattr hoặc vars(concurrent)['futures'] trong báo cáo. Theo dõi cách các tên được thu thập trong quá trình pickling và xác minh rằng một hàm đã được dump có thể được tải trong một session khác và được gọi thành công khi tên submodule được truy cập gián tiếp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 1.9k
- Fork
- 197
- Merge trung bình
- 1 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cloudpipe/cloudpickle
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cloudpipe/cloudpickle#593 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
cloudpipe/cloudpickle#595 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
cloudpipe/cloudpickle#592 · 2 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
cloudpipe/cloudpickle#589 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
cloudpipe/cloudpickle#587 ·
Tất cả issue của cloudpipe/cloudpickle
Issue tương tự
-
needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
openvinotoolkit/openvino_notebooks#3665 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày
-
docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
benchmark-gap
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày