python / python/cpython

Allow `multiprocessing` Servers to return non-callables

Aperta
#118,231 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

topic-multiprocessing type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in Lib/multiprocessing/managers.py, nella logica di recupero di Server collegata nell’issue. Traccia il modo in cui l’accesso agli attributi del proxy distingue tra valori chiamabili e valori restituiti, incluso il caso di un attributo mancante e il percorso di creazione del proxy. Il lavoro è completato quando le variabili membro dell’istanza e i getter delle proprietà possono essere recuperati senza reimplementazione, mantenendo invariato il comportamento esistente dei valori chiamabili.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
distributed-systems
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.