Skip to content

[3.13] gh-157672: Keep Python's signal handlers when Tk is initialized on macOS (GH-157673) - #157989

Merged
serhiy-storchaka merged 2 commits into
python:3.13from
serhiy-storchaka:bp-157672-3.13
Sep 23, 2026
Merged

serhiy-storchaka merged 2 commits into
python:3.13from
serhiy-storchaka:bp-157672-3.13

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Tk on macOS replaces the SIGINT, SIGHUP and SIGTERM handlers with its own, which exits the process, so Ctrl-C terminated a tkinter program instead of raising KeyboardInterrupt. Save the handlers installed by Python before Tk_Init() and restore them after it.

This affects Tk 8.6.11 to 8.6.18 and 9.0 to 9.0.4. Tk itself is fixed in 8.6.19 and 9.0.5.

(cherry picked from commit 4532b36)

Manual backport: this branch has no Tkinter_TkInit() wrapper, so the helper is added and both Tk_Init() call sites go through it.

… on macOS (pythonGH-157673)

Tk on macOS replaces the SIGINT, SIGHUP and SIGTERM handlers with its
own, which exits the process, so Ctrl-C terminated a tkinter program
instead of raising KeyboardInterrupt.  Save the handlers installed by
Python before Tk_Init() and restore them after it.

This affects Tk 8.6.11 to 8.6.18 and 9.0 to 9.0.4.  Tk itself is fixed
in 8.6.19 and 9.0.5.

(cherry picked from commit 4532b36)
On 3.13 there was no Tkinter_TkInit(), and tkappinit.c, which is used
when Python is built with WITH_APPINIT (as on macOS), called Tk_Init()
directly, bypassing the fix.
@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) September 23, 2026 11:21
@serhiy-storchaka
serhiy-storchaka merged commit 159a360 into python:3.13 Sep 23, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant