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

Backend hook function for shutting down/cleaning up backend #719

Closed
HenrikBengtsson opened this issue Apr 5, 2024 · 1 comment
Closed
Milestone

Comments

@HenrikBengtsson
Copy link
Owner

Currently, changing plan as in:

plan(multisession, workers = 2)
plan(sequential)

will trigger a call to an internal plan_cleanup() function:

  plan_cleanup <- function() {
    ClusterRegistry(action = "stop")
  }

As we can see, this function will stop any cluster futures. That is, it works for plan(cluster, ...) and plan(multisession, ...) and derivatives, but that's it.

We could add support for custom cleanup "hook" functions so we can support shutdown of all backends. One approach could be to designate an special attribute for the "evaluator" function, e.g.

attr(cluster, "cleanup") <- function() {
  future::ClusterRegistry(action = "stop")
}

attr(multisession, "cleanup") <- function() {
  future::ClusterRegistry(action = "stop")
}

Then, we could do something like:

  plan_cleanup <- function() {
    evaluator <- oldStack[[1L]]
    cleanup <- attr(evaluator, "cleanup", exact = TRUE)
    if (is.function(cleanup)) {
      cleanup()
    }
  }
@HenrikBengtsson
Copy link
Owner Author

Completed. Added R option future.plan.cleanup.legacy (default FALSE) that can be set to TRUE to force the past behavior of calling ClusterRegistry(action = "stop") regardless of future plan currently set.

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

No branches or pull requests

1 participant