Repository navigation
gh-157672: Keep Python's signal handlers when Tk is initialized on macOS - #157673
Conversation
… 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.
|
Thank you for merging the fix on upstream @culler. Here is a workaround on the Tkinter side. I think it will not harm to have both. On other hand, we build Python on macOS with specific versions of Tk, so if they contain that fix, it may be redundant. |
|
The patch was backported to Tk 9.0, which I guess means that the workaround will be become redundant on new Python releases. I agree that the redundancy will probably not cause any problems. |
|
I merged it in into core-8-6-branch as well. But we cannot guarantee that the distributor will update Tcl/Tk to versions containing that fix. |
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
GH-157987 is a backport of this pull request to the 3.15 branch. |
|
GH-157988 is a backport of this pull request to the 3.14 branch. |
|
GH-157989 is a backport of this pull request to the 3.13 branch. |
…d on macOS (GH-157673) (GH-157988) 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)
…d on macOS (GH-157673) (GH-157989) 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.
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 beforeTk_Init()and restore them after it. Handlers which areSIG_DFLare 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