python / python/cpython

Subinterpreters running on the main thread should handle signals

Aberta
#137,173 4 comentários 1 reação 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

interpreter-core topic-subinterpreters 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:

It's currently impossible to interrupt long-running operations inside subinterpreters:

from concurrent import interpreters

interp = interpreters.create()
interp.exec("import time; time.sleep(100)")  # Cannot CTRL^C!

This is because _Py_ThreadCanHandleSignals explicitly requires the main interpreter:

https://github.com/python/cpython/blob/7040aa54f14676938970e10c5f74ea93cd56aa38/Include/internal/pycore_pystate.h#L82-L86

After thinking about this for a while, I can't see any real reason why stdlib interpreters shouldn't be able to handle signals (in the main thread). It's probably a slight compatibility break for legacy C API subinterpreters, so we can just disable it for them (and add the new option to handle signals behind an interpreter configuration setting).

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

Quickly discussed in-person a few months ago with @ericsnowcurrently and @colesbury. I don't think we came to a consensus, but there wasn't any pushback as far as I could tell.

Linked PRs
  • gh-137174

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

Leia Include/internal/pycore_pystate.h em _Py_ThreadCanHandleSignals e o exemplo de concurrent.interpreters na issue. Revise o PR vinculado gh-137174 antes de prosseguir; isso permitiria que Ctrl-C interrompesse operações de longa duração em subinterpretadores da thread principal, preservando a compatibilidade com a C API legada indicada.

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

Avaliação

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