python / python/cpython

`threading.Thread`'s group parameter is a nuisance

Aperta
#155,348 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

For some background: on DPO, someone suggested a threading.run function. I was in favor of the idea on the basis that threading.Thread has a clunky constructor. That aside, I think we can try to improve it.

In particular, the group parameter is an annoying sharp edge. It's the first positional argument, so threading.Thread(my_function) doesn't work, and instead you get a cryptic error message saying group argument must be None for now. I've fallen victim to this many times.

The docs say that group is reserved for a future ThreadGroup class:

group must be None as it is reserved for future extension when a ThreadGroup class is implemented.

I did some digging, and it seems it was proposed to add a ThreadGroup back in 2014: #66212. Many were not in favor of the idea, as it looked like a worse version of ThreadPoolExecutor. Other than the existence of this parameter, I can't see much reason to ever add a ThreadGroup. So, what do we do about group?

I think it's feasible to deprecate and remove it entirely. We can do this by changing the default group parameter to a private sentinel value, and then if a user passes anything to it (including None), we emit a deprecation warning. In five years, we remove the parameter, making target the first positional parameter and thus allowing Thread(my_function) to work.

Most people use the threading.Thread(target=...) pattern for creating threads, and they won't be broken by a deprecation or a removal. For the people who do use the Thread(None, function) pattern, migrating is fairly trivial.

What do others think? Would a removal result in too much breakage?

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 dal costruttore di threading.Thread e dalla relativa documentazione, quindi esamina la issue #66212 e la discussione DPO collegata per individuare le precedenti considerazioni di progettazione. Determina il comportamento di compatibilità, degli avvisi e della migrazione per gli usi posizionali esistenti; il lavoro sarà completato quando ci sarà accordo sul fatto che il parametro group debba essere deprecato e su come rimuoverlo.

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

Valutazione

Stack tecnologico
python
Ambito
operating-systems
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.