Allow `multiprocessing` Servers to return non-callables
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en Lib/multiprocessing/managers.py, en la lógica de recuperación de Server enlazada en el issue. Rastrea cómo el acceso a los atributos del proxy distingue entre valores invocables y valores devueltos, incluido el caso de un atributo inexistente y la ruta de creación del proxy. El trabajo estará terminado cuando las variables miembro de instancia y los getters de propiedades puedan recuperarse sin reimplementación, mientras se mantiene el comportamiento existente para los valores invocables.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- distributed-systems
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100