python / python/cpython

An interpreter can start running during `_interpreters.destroy`

Aberta
#127,041 0 comentários 1 reação 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

3.13 3.14 extension-modules topic-subinterpreters type-crash
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

Crash report

What happened?

Now that gh-126914 is out of the way, we can try and deal with some of the other issues related to multithreading and subinterpreters that couldn't get dealt with before. Namely, the is_running_main inside _interpreters.destroy doesn't account for the fact that the interpreter could start running again by another thread after that check has already passed.

Quick reproducer:

from threading import Thread
import _interpreters

interp = _interpreters.create()


def run():
    _interpreters.run_string(interp, "1")
    _interpreters.destroy(interp)


threads = [Thread(target=run) for _ in range(1000)]
for thread in threads:
    thread.start()

for thread in threads:
    thread.join()

I think the simplest fix would be to just disallow a subinterpreter from ever set "running main" again after that check has finished. I implemented this already in the (closed) gh-126696, but I'd like to try and refactor that a bit before just copying things over to a new PR.

cc @ericsnowcurrently, let me know if you have a better approach.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

No response

Linked PRs
  • gh-127044

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 caminho _interpreters.destroy e pela verificação is_running_main, depois execute o reprodutor com 1.000 threads usando _interpreters.run_string e _interpreters.destroy. Revise o PR vinculado gh-127044 e o gh-126696 fechado referenciado; considera-se concluído quando o reprodutor não permitir mais que um interpretador comece a executar durante a destruição.

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

Avaliação

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

Receba novas issues na sua caixa de entrada

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