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 Process.on_terminate #13694

Merged

Conversation

stakach
Copy link
Contributor

@stakach stakach commented Jul 22, 2023

This fixes some inconsistences between the platforms

  • previously the unix implementation was not ignoring the interrupt whilst the windows version is.

Also improves usefulness

  • handles ctrl-c, terminal closed and user session ending interrupts

Replaces #13654 as I screwed up my rebase

Resolves #13983

@stakach
Copy link
Contributor Author

stakach commented Aug 18, 2023

@HertzDevil @straight-shoota what do you think?

@m-o-e
Copy link
Contributor

m-o-e commented Sep 17, 2023

This impl suffers from the same problem that is described for Signal#trap here: #13803

src/process.cr Outdated Show resolved Hide resolved
@HertzDevil
Copy link
Contributor

This PR is independent from #13803, although the relative positions between the previous handler parameter and the reason parameter could introduce a breaking change if not done carefully.

src/process.cr Outdated Show resolved Hide resolved
@stakach
Copy link
Contributor Author

stakach commented Nov 13, 2023

Any thoughts on this one? Would be nice to simplify this situation:

  {% if flag?(:win32) %}
    Process.on_interrupt { shutdown_gracefully }
  {% else %}
    # Detect ctr-c
    Signal::INT.trap { shutdown_gracefully }

    # Docker containers use the term signal
    Signal::TERM.trap { shutdown_gracefully }
  {% end %}

@straight-shoota
Copy link
Member

It would be preferrable to discuss the problem in an independent issue and then think about potential solutions. Being presented with an implemented solution without a detailled and open analysis of the issue it tries to solve may hinder the problem solving process. It's great that you already did the impementation work. And making concrete suggestions is certainly helpful. But a pull request with a concrete implementation isn't a great place to discuss solution strategies openly.
For this reason we ask to open an issue first before opening a pull request.
This topic might seem trivial, but I don't think it is. At least not the part of integrating it into the existing API (and pending parallel API changes like #13803).

The previous comment shows a great example of why this is useful. I've created issue #13983 so we can talk independent of this particular implementation. Until that's come to a conclusion, this PR should be a draft.

@straight-shoota straight-shoota marked this pull request as draft November 14, 2023 19:49
@@ -58,10 +58,35 @@ struct Crystal::System::Process
raise RuntimeError.from_errno("kill") if ret < 0
end

@[Deprecated("Use `#on_terminate` instead")]
Copy link
Member

Choose a reason for hiding this comment

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

thought: IMO it would not necessary to deprecate this method. It's just the backend of Process.on_interrupt and should never be called directly. It doesn't hurt to have the deprecation, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I put it there so it would be simpler to find and remove at a later date. Let me know if you want me to remove

Copy link
Member

Choose a reason for hiding this comment

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

No, I think it's fine. Thanks!

src/process.cr Outdated Show resolved Hide resolved
src/process.cr Show resolved Hide resolved
stakach and others added 2 commits January 24, 2024 13:12
Co-authored-by: Johannes Müller <[email protected]>
Co-authored-by: Johannes Müller <[email protected]>
@stakach
Copy link
Contributor Author

stakach commented Feb 2, 2024

@HertzDevil what do you think?

src/process/status.cr Show resolved Hide resolved
@stakach
Copy link
Contributor Author

stakach commented Feb 7, 2024

@HertzDevil any further changes you can think of?

@straight-shoota straight-shoota added this to the 1.12.0 milestone Feb 26, 2024
@straight-shoota straight-shoota changed the title improve Process#on_interrupt Add Process.on_terminate Feb 26, 2024
@straight-shoota straight-shoota merged commit c6bae60 into crystal-lang:master Feb 27, 2024
57 checks passed
@crysbot
Copy link

crysbot commented Mar 26, 2024

This pull request has been mentioned on Crystal Forum. There might be relevant details there:

https://forum.crystal-lang.org/t/upcoming-1-12-0-release/6714/1

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.

Improve Process.on_interrupt for handling more process termination signals
9 participants