tkinter: Tk on macOS replaces Python's SIGINT, SIGHUP and SIGTERM handlers, so Ctrl-C exits instead of raising KeyboardInterrupt
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Since Tk 8.6.11, TkpInit() on macOS installs its own C-level handler for SIGINT, SIGHUP and SIGTERM, which calls Tcl_Exit(1) (tkMacOSXInit.c, Tk ticket f3e96942ed). It does this unconditionally, so Python's handler is replaced as soon as a Tk instance is created. signal.getsignal() still returns the Python handler, but it is never called.
import signal, time, tkinter
print(signal.getsignal(signal.SIGINT)) # <built-in function default_int_handler>
root = tkinter.Tk()
time.sleep(60) # press Ctrl-C
On macOS the process exits silently with status 1 instead of raising KeyboardInterrupt. Python-level handlers set with signal.signal() for SIGTERM and SIGHUP are disabled the same way.
This also affects IDLE: with #157662, which interrupts user code with a real SIGINT, Ctrl-C in the Shell would terminate the user process on macOS once the user's code has created a Tk window. On the macOS CI the test_idle worker exits with status 1 for the same reason, since GUI tests earlier in the same process created Tk windows.
The fix on the Tk side is on branch mac-signal-handlers, but installed Tk builds will not have it for a long time. _tkinter should save the handlers of these signals before Tk_Init() and restore them after it.
Linked PRs
- gh-157673
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en _tkinter, en la llamada a Tk_Init(), y rastrea cómo se ven afectados los manejadores de señales de macOS. Reproduce el problema con el script de tkinter proporcionado y, después, verifica que crear una instancia de Tk conserve los manejadores de Python y que Ctrl-C genere una KeyboardInterrupt.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- desktop
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100