Skip to content

Add default interrupt handlers#13568

Merged
straight-shoota merged 4 commits intocrystal-lang:masterfrom
straight-shoota:feature/default-signal-trap
Jun 27, 2023
Merged

Add default interrupt handlers#13568
straight-shoota merged 4 commits intocrystal-lang:masterfrom
straight-shoota:feature/default-signal-trap

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.

@beta-ziliani beta-ziliani requested a review from HertzDevil June 26, 2023 14:30
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
@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