-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
improve Process#on_interrupt #13654
improve Process#on_interrupt #13654
Conversation
handle user and system interrupts
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
src/crystal/system/win32/process.cr
Outdated
@@ -103,7 +103,7 @@ struct Crystal::System::Process | |||
def self.on_interrupt(&@@interrupt_handler : ->) : Nil | |||
restore_interrupts! | |||
@@win32_interrupt_handler = handler = LibC::PHANDLER_ROUTINE.new do |event_type| | |||
next 0 unless event_type.in?(LibC::CTRL_C_EVENT, LibC::CTRL_BREAK_EVENT) | |||
next 0 unless event_type.in?(LibC::CTRL_C_EVENT, LibC::CTRL_BREAK_EVENT, LibC::CTRL_CLOSE_EVENT, LibC::CTRL_LOGOFF_EVENT, LibC::CTRL_SHUTDOWN_EVENT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest moving these into a constant for readability purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably remove the line entirely as I'm pretty sure these are all the possible events
The original idea of |
Yeah I understand what you're saying but a cross platform way to handle just ctrl-c is not very useful. Like what's the difference between pressing ctrl-c and closing the terminal window from a users perspective. Also if I shutdown my computer or ask docker to stop (SIGTERM) or my ssh session exits I want the app to exit cleanly and it doesn't make sense to have the developer have to deal with all the different cases, on each platform, as the default. Sure if you want some special behaviour do it the hard way, but the cross platform helper should handle all that for you. I also get that
maybe we just pass the constant value? but then it gets very platform specific again and currently won't compile on unix Process.on_interrupt do |code|
case code
when Signal::INT, LibC::CTRL_C_EVENT?
end
end unless we alias the window symbols in something like what ruby does when running on windows
also worth noting that ruby, rust and go lang all only support |
Co-authored-by: Johannes Müller <[email protected]>
closed in favour of #13694 |
This fixes some inconsistences between the platforms
Also improves usefulness
effectively this function becomes the termination requested callback
the previous implementation meant that you would still have to implement quite a bit of system specific code to handle the other signals
Example of the state of this function before this pull