Allow `multiprocessing` Servers to return non-callables
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Lib/multiprocessing/managers.py の、issue でリンクされている Server の取得ロジックから始めます。proxy の属性アクセスが、呼び出し可能な値と返される値をどのように区別しているかを、属性が存在しない場合と proxy 作成経路を含めて追跡します。インスタンスメンバー変数とプロパティ getter を再実装なしで取得でき、既存の呼び出し可能な値の動作が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- distributed-systems
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100