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

Exit R gracefully exits the Reticulate Python session #5100

Closed
wants to merge 5 commits into from

Conversation

dfalbel
Copy link
Contributor

@dfalbel dfalbel commented Oct 22, 2024

Addresses #5083
Requires Ark side: posit-dev/ark#603
This is built on top of #5056 so should merge it before this one.

In the Ark side we added a finalizer using reg.finalizer to the reticulate namespace. So whenever the reticulate namespace is unloaded (or when the R session is about to exit), we'll send a shutdown event to the reticulate extension. The R side waits for the event to be processed and for the comm client to be disposed before really finalizing the session. Thus making sure that the reticulate Python session has gracefully exited before ending the R session - which would cause IPykernel to crash otherwise.

I'm not sure this is the best approach although it's the one that doesn't need to introduce any new concepts.
We could also:

  1. Add API's to register shutdown callbacks to positron.RuntimeSession, these callbacks would be await before calling the session shutdown routines.

  2. Perhaps exposing the Exiting RuntimeState. Although this might not be enough, because we really need to wait for the Python session to end before proceeding.

    /** The runtime is in the process of shutting down. */
    Exiting = 'exiting',

  3. Introducing the concept of parent/child sessions and 'parents' would be resposnible for shutting down their child sessions before shutting them down.

@jmcphers do you have a sense if the current approach is reasonable?

@dfalbel dfalbel closed this Nov 14, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant