-
Notifications
You must be signed in to change notification settings - Fork 79
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 restarting behavior of the reticulate session. #5019
Conversation
} | ||
}); | ||
|
||
await this.shutdown(positron.RuntimeExitReason.SwitchRuntime); |
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.
Should this be ExitReason.Restart?
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.
If we send a ExitReason.Restart
the Jupyter Adapter will try to reinitialize it as soon as it exitted, but we actually want to wait for the new R session to be started.
positron/extensions/jupyter-adapter/src/LanguageRuntimeAdapter.ts
Lines 901 to 914 in 4a84983
if (this._restarting) { | |
this._kernel.clearSession(); | |
this._restarting = false; | |
// Defer the start by 500ms to ensure the kernel has processed its | |
// own exit before we ask it to restart. This also ensures that the | |
// kernel's status events as it starts up don't overlap with the | |
// status events emitted during shutdown (which can happen on the | |
// Positron side due to internal buffering in the extension host | |
// interface) | |
setTimeout(() => { | |
this._kernel.start(); | |
}, 500); | |
} | |
} |
My reasonming was that this 'looks like' we are effectively switching runtimes, as we don't preserve the session RuntimeSessionObject, etc. Maybe RuntimeExitReason.Shutdown
is better?
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.
Approving since this does make things better but in my testing I noticed some intermittent issues that my be worth investigating.
First, this happened intermittently on restart:
Failed to initialize and connect to the Reticulate Python session: Cannot invoke 'reticulate_start_kernel'; no UI comm is open.
Secondly, during the restart I sometimes found that R and Python both got stuck "restarting" (according to the console toolbar) even when the restart was finished. Might be a UI bug since eventually you could use the kernels and the next operation cleared the restarting status.
I could reproduce and after some testing I figured I accidentally commited the experiment with setting this to Should be working great now. I can no longer reproduce both issues. |
Addresses #4887 by making sure the correct order of action happens:
We also added a new dialog when restarting the reticulate kernel, to make sure that the user is aware that the R kernel is also restarting, not just the reticulate kernel.
We can't restart the reticulate kernel without restarting the R session because Reticulate binds to a single Python session only once. If simply restarted Ipykernel, it would still point to the same Python session as before (eg same variables, etc).