Allow `multiprocessing` Servers to return non-callables
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in Lib/multiprocessing/managers.py bei der im issue verknüpften Server-Abruflogik. Verfolge, wie der Zugriff auf Proxy-Attribute zwischen aufrufbaren Werten und zurückgegebenen Werten unterscheidet, einschließlich des Falls eines fehlenden Attributs und des Pfads zur Proxy-Erstellung. Als abgeschlossen gilt die Arbeit, wenn Instanzmitgliedsvariablen und Property-Getter ohne Neuimplementierung abgerufen werden können, während das bestehende Verhalten für aufrufbare Werte erhalten bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- distributed-systems
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100