python / python/cpython

Allow `multiprocessing` Servers to return non-callables

Aberta
#118,231 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

topic-multiprocessing type-feature
Linguagem predominante
Python
Estrelas
77.2k
Forks
35.9k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

Feature or enhancement

Proposal:

The logic for the multiprocessing Server class is the following for retrieving values from an instance referenced by a proxy:

https://github.com/python/cpython/blob/7d369d471cf2b067c4d795d70b75201c48b46f5b/Lib/multiprocessing/managers.py#L273-L286

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece em Lib/multiprocessing/managers.py, na lógica de recuperação de Server vinculada na issue. Rastreie como o acesso a atributos do proxy distingue valores chamáveis de valores retornados, incluindo o caso de um atributo ausente e o caminho de criação do proxy. O trabalho estará concluído quando variáveis-membro da instância e getters de propriedades puderem ser recuperados sem reimplementação, mantendo intacto o comportamento existente dos valores chamáveis.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
distributed-systems
Tipo de issue
Funcionalidade
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.