python / python/cpython

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

Aberta
#155,348 2 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

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

Descrição

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?

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 pelo construtor de threading.Thread e pela documentação vinculada a ele; em seguida, analise a issue #66212 e a discussão de DPO vinculada para verificar as preocupações de design anteriores. Determine o comportamento de compatibilidade, avisos e migração para os usos posicionais existentes; o trabalho estará concluído quando houver acordo sobre se e como o parâmetro group deve ser descontinuado e removido.

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

Avaliação

Stack de tecnologia
python
Domínio
operating-systems
Tipo de issue
Funcionalidade
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Pouca atividade
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.