Fix exit
from Python console within reticulate sessions
#5056
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses #5022, #4982 and #5144
Positron detects that the session is closed whenever the zeroMQ sockets are closed, triggering UI updates, etc.
Reticulate Python sessions are managed within the R process, thus when exitting the IPykernel, the process is not necessarily closed - which would make sure the zeroMQ sockets are also closed.
This PR makes sure that the IPyKernel closes the zeroMQ sockets before exitting.
While this PR fixes the initial issue, it uncovers a another issue that I still couldn't figure out how to fix, but have some understanding of what's happening:
If you create a Reticulate Python session, then shut it down (either by typing
exit
or clicking the shutdown button) and then restart the reticulate python session, the LSP for that second session will never correctly start. It seems it gets stuck in theStarting
state.This is problematic because the next time you click on
Shutdown
to close the Python session it will be stuck again.The reason is that the shutdown routine in:
positron/extensions/positron-python/src/client/positron/session.ts
Lines 386 to 394 in 66c7015
Tries to
deactivate
the LSP, which then blocks in:positron/extensions/positron-python/src/client/positron/lsp.ts
Lines 183 to 187 in 66c7015
@seeM I suspect that there's still some state that is not completely cleaned up when the IPyKernel exits that's causing
the LSP to not start correctly. I spent a good ammount of time trying to figure out what's happening but could not find yet. Do you have suggestions for where to look at? I'm pretty sure that the sockets are created in:
positron/extensions/positron-python/python_files/positron/positron_ipykernel/lsp.py
Lines 30 to 52 in a410174
And we are somehow waiting for:
positron/extensions/positron-python/src/client/positron/lsp.ts
Lines 125 to 155 in a410174
Because we never reach the
State.Running
, but we do getState.Starting
.