Skip to content

gh-157672: Keep Python's signal handlers when Tk is initialized on macOS - #157673

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-157672-tk-signals
Open

serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-157672-tk-signals

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Tk on macOS replaces the SIGINT, SIGHUP and SIGTERM handlers with its own, which exits the process with status 1, so Ctrl-C terminated a tkinter program instead of raising KeyboardInterrupt, and Python-level handlers of SIGTERM and SIGHUP stopped working. Save the handlers installed by Python before Tk_Init() and restore them after it. Handlers which are SIG_DFL are not restored, which matches the fix on the Tk side (branch mac-signal-handlers): Tk's handler is only kept for signals which Python does not handle.

The test runs in a subprocess, because the process exits without the fix.

🤖 Generated with Claude Code

… on macOS

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant