Skip to content

bootloader: Windows: implement handling of console ctrl signals - #6935

Merged
Legorooj merged 2 commits into
pyinstaller:developfrom
rokm:win-console-ctrl-handler
Jul 10, 2022
Merged

Legorooj merged 2 commits into
pyinstaller:developfrom
rokm:win-console-ctrl-handler

Conversation

@rokm

@rokm rokm commented Jul 9, 2022 •

Copy link
Copy Markdown
Member

Remove the ingoring of SIGABRT, SIGINT, SIGTERM, and SIGBREAK in Windows codepath for the parent process of the onefile mode, and replace it with handling of Windows-specific console control signals. Ignoring SIGABRT has little value, as it is usually generated by abnormal conditions within the process (e.g., code calling abort() due to failing validation); so ignoring it is
akin to ignoring bugs in the bootloader code. SIGTERM is, as per MSDN, never generated on Windows (although it could be raised programmatically?). And ignoring SIGINT and SIGBREAK prevents us from properly processing the corresponding console control signals.

For onefile parent process, install the console ctrl signal handler using the SetConsoleCtrlHandler win32 API function. The installed handler suppresses CTRL_C_EVENT and CTRL_BREAK_EVENT signals, which should be equivalent of the old SIGINT and SIGBREAK suppression. But it also delays the parent process' termination in cases of CTRL_CLOSE_EVENT (user closing the parent console window), CTRL_LOGOFF_EVENT (user logging off), and CTRL_SHUTDOWN_EVENT (system shutting down), in an attempt to buy time for the child process to exit and for the main thread of the parent process to perform the clean-up of the temporary directory.

Closes #6591 and addresses the Windows-centric bits that were added into #2379.

rokm added 2 commits July 10, 2022 18:42
Remove the ingoring of SIGABRT, SIGINT, SIGTERM, and SIGBREAK in
Windows codepath for the parent process of the onefile mode, and
replace it with handling of Windows-specific console control
signals. Ignoring SIGABRT has little value, as it is usually
generated by abnormal conditions within the process (e.g., code
calling `abort()` due to failing validation); so ignoring it is
akin to ignoring bugs in the bootloader code. SIGTERM is, as per
MSDN, never generated on Windows (although it could be raised
programmatically?). And ignoring SIGINT and SIGBREAK prevents us
from properly processing the corresponding console control signals.

For onefile parent process, install the console ctrl signal handler
using the `SetConsoleCtrlHandler`  win32 API function. The installed
handler suppresses CTRL_C_EVENT and CTRL_BREAK_EVENT signals, which
should be equivalent of the old SIGINT and SIGBREAK suppression.
But it also delays the parent process' termination in cases of
CTRL_CLOSE_EVENT (user closing the parent console window),
CTRL_LOGOFF_EVENT (user logging off), and CTRL_SHUTDOWN_EVENT
(system shutting down), in an attempt to buy time for the child
process to exit and for the main thread of the parent process to
perform the clean-up of the temporary directory.
Document the newly added handling of Windows console control signals
and the shutdown behavior when using Ctrl+C/Ctrl+Break, closing the
console, or trying to shut down the frozen application from the
Task Manager.
@rokm
rokm force-pushed the win-console-ctrl-handler branch from d63d9c1 to ef47a6b Compare July 10, 2022 16:46
@rokm
rokm marked this pull request as ready for review July 10, 2022 16:49
@Legorooj
Legorooj enabled auto-merge (rebase) July 10, 2022 18:28
@Legorooj
Legorooj merged commit 1e6298d into pyinstaller:develop Jul 10, 2022
@rokm
rokm deleted the win-console-ctrl-handler branch July 10, 2022 21:13
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let the bootloader send a SIGINT to the python process for cleanup functions etc

3 participants