Allow `multiprocessing` Servers to return non-callables
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Feature or enhancement
Proposal:
The logic for the multiprocessing Server class is the following for retrieving values from an instance referenced by a proxy:
It works well the majority of the time, but it fails when trying to get something that doesn't immediately return a callable (it can probably be a bit more specific when it comes to what type of callable it is). A change like the following would yield more robust behavior from a base point of view and wouldn't require reimplementation in a subclass:
value_or_function = getattr(obj, methodname, SENTINEL)
if value_or_function is SENTINEL:
raise AttributeError(f"Type '{obj.__class__.__name__}' has no attribute named '{methodname}'")
if isinstance(value_of_function, typing.Callable):
try:
res = value_or_function(*args, **kwds)
except Exception as e:
msg = ('#ERROR', e)
else:
typeid = gettypeid and gettypeid.get(methodname, None)
if typeid:
rident, rexposed = self.create(conn, typeid, res)
token = Token(typeid, self.address, rident)
msg = ('#PROXY', (rexposed, token))
else:
msg = ('#RETURN', res)
else:
msg = ('#RETURN', value_or_function)
There are likely edge cases that the above does not account for, but a change similar to the one above will open up the use of instance member variables and getters for properties.
A value for SENTINEL (or better) would obviously have to be defined somewhere (it's not in the example).
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Hướng dẫn đóng góp
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.
Hướng nghiên cứu
Bắt đầu trong Lib/multiprocessing/managers.py, tại logic truy xuất Server được liên kết trong issue. Theo dõi cách việc truy cập thuộc tính proxy phân biệt các giá trị có thể gọi với các giá trị được trả về, bao gồm trường hợp thuộc tính bị thiếu và đường dẫn tạo proxy. Công việc được xem là hoàn tất khi các biến thành viên của instance và các property getter có thể được truy xuất mà không cần triển khai lại, đồng thời vẫn giữ nguyên hành vi hiện có của các giá trị có thể gọi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- distributed-systems
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100