Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default interrupt handlers #13568

Conversation

straight-shoota
Copy link
Member

Resolves #8687

@HertzDevil
Copy link
Contributor

On Windows this works when run alone:

lib LibC
  fun GenerateConsoleCtrlEvent(dwCtrlEvent : DWORD, dwProcessGroupId : DWORD) : BOOL
end

at_exit { print "Exiting" }
print "."
STDOUT.flush
LibC.GenerateConsoleCtrlEvent(LibC::CTRL_C_EVENT, 0)
sleep

However it also sends Ctrl+C to the spec process itself, effectively aborting the spec. SIGBREAK might be possible to test but that requires passing CREATE_NEW_PROCESS_GROUP to CreateProcessW

@straight-shoota
Copy link
Member Author

I suppose we could put that in spec/manual.

@straight-shoota
Copy link
Member Author

Even a manual spec needs a functioning spec harness which doesn't work when the process gets cancelled from inside an example.
So I added the code only in a comment next to the other specs. That should be good enough.

Copy link
Contributor

@HertzDevil HertzDevil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be noted that restore_interrupts! does not restore this default interrupt handler (or maybe it should?)

@straight-shoota straight-shoota added this to the 1.9.0 milestone Jun 26, 2023
@straight-shoota straight-shoota merged commit 742d920 into crystal-lang:master Jun 27, 2023
48 of 50 checks passed
@straight-shoota straight-shoota deleted the feature/default-signal-trap branch July 10, 2023 16:59
straight-shoota added a commit that referenced this pull request Jul 18, 2023
@straight-shoota
Copy link
Member Author

This was eventually reverted in #13673 due to complications mentioned in #13672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

at_exit is not triggered by SIGINT and SIGTERM
2 participants