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 flag to register shutdown hooks for os.call and os.spawn APIs, overhaul destroy APIs #324

Merged
merged 8 commits into from
Oct 21, 2024

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Oct 20, 2024

  • Backports the functionality from Mill to allow us to register shutdown hooks such that when the parent process terminates the subprocesses are shut down as well. This allows the same logic to be used consistently across all .call and .spawn invocations

  • Consolidate SubProcess#destroy and SubProcess#destroyForcibly into a single SubProcess#destroy method which takes some default parameters, allowing the user to choose async = true or configure the shutdownGracePeriod: Long.

  • The default behavior of SubProcess#destroy has changed to block on the subprocess actually exiting, which I think is more intuitive. The old behavior is available under destroy(async = true)

Best reviewed with Hide whitespace. Added some simple unit tests to assert the new functionality, existing unit tests should assert on existing workflows

@lihaoyi lihaoyi changed the title Add flag to register shutdown hooks for os.call and os.spawn APIs Add flag to register shutdown hooks for os.call and os.spawn APIs, overhaul destroy APIs Oct 20, 2024
@lihaoyi lihaoyi requested review from lefou and lolgab October 20, 2024 07:28
Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

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

I think we should rename shutdownHook to something like exitWithJvm or stopWithJvm. We don't really support any custom shtudown hook. We just use the shutdown hook mecahnism internally to stop the process when the JVM is stopped.

@lihaoyi
Copy link
Member Author

lihaoyi commented Oct 20, 2024

Ended up going with destroyOnExit, to match the existing os.temp(deleteOnExit = true) and .destroy() methods

@@ -1725,7 +1725,9 @@ os.call(cmd: os.Shellable,
mergeErrIntoOut: Boolean = false,
timeout: Long = Long.MaxValue,
check: Boolean = true,
propagateEnv: Boolean = true): os.CommandResult
propagateEnv: Boolean = true,
shutdownGracePeriod: Long = 100,
Copy link
Member

Choose a reason for hiding this comment

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

What's the time unit used for shutdownGracePeriod? Should we name it shutdownGracePeriodMsec?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll probably leave it as is, the scaladoc says it's in milliseconds so that should be enough

destroyOnExit = destroyOnExit
)
}
def apply(
Copy link
Member

Choose a reason for hiding this comment

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

Is this only provided for bin-compat? Shouldn't we deprecate it therefore?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've had issues with @deprecated things being accidentally resolved here before, but will add a comment like the other forwarders

destroyOnExit = destroyOnExit
)
}
def apply(
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this one is only for bin-compat, so we should deprecate it for removal.

@lihaoyi lihaoyi merged commit 383964d into main Oct 21, 2024
8 checks passed
@lihaoyi lihaoyi deleted the shutdown-hook branch October 21, 2024 01:23
lihaoyi added a commit to com-lihaoyi/mill that referenced this pull request Oct 21, 2024
@lefou lefou added this to the 0.11.3 milestone Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants