-
Notifications
You must be signed in to change notification settings - Fork 293
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
Allow for Kernel Management (view and shutdown running kernels both local and remote) #1378
Comments
Thanks for filing this issue. We'll discuss these feature requests in our triage meeting |
I'd like to voice agreement, as I have the same frustrations, as do others I have introduced vscode notebooks too. Perhaps the key issue for me is a subset of @nikitakit's concerns: It's extremely difficult to have a persistent kernel across ssh disconnects, vscode restarts, closing the jupyter tab, etc. Ideally, I would like to use VSCode's jupyter notebooks the way I use Jupyter notebooks in the browser: When I open a notebook, a kernel is started which is associated with that notebook. Regardless of whether I close the tab, close my browser, or restart my laptop (assuming the Jupyter server is running remotely), when I re-open the notebook, the same kernel will be used. This is incredibly helpful, even in simple settings where code may take ~15 mins to run and I want to put my laptop to sleep and get coffee. (Please let me know if there is an existing way to do this, or if this is the wrong place to post!) |
Theoretically (haven't tested it) if you start the notebook server yourself and then pick it as a remote server, the notebook should reconnect to the same kernel on reopening (we save the live kernel id for remote sessions). |
The problem with implementing this the way Jupyter does is that there's nothing that would shutdown the server (if we start it). In your example of using the browser, you (or somebody else) started the Jupyter server. You're responsible for shutting it down. In the case where we start the jupyter server (or just the kernel as we do now), we need to close it down at some point. Would it work if we didn't close kernels on notebook close, but rather only when shutting down VS code? I guess I'm asking if when you take a break from VS code do you leave it running? I believe if we didn't shutdown kernels on notebook close, the sleep of notebook wouldn't shutdown the kernel (could be wrong though, depends upon what VS code does to the extension host process on sleep). |
I believe preview-notebook doesn't work with remote so well. Can you try with the original notebook editor? What should have happened is:
|
This should already be happening for remote servers. We only kill kernels for local (owned by us) sessions. For local, we currently close the kernels when closing the window associated with a notebook. We could delay this until the whole of VS code shuts down. |
Huh, you're totally right, my bad. I just tried steps 1-4 again with the Edit: I originally said it was the preview notebook, but I was actually using the standard one. This does not work with the preview notebook. |
Quick update: I realized I was using the standard notebook, not the preview notebook when I posted above. The preview notebook doesn't seem to use the same kernel after a reload; is there an existing bug I can follow for this? I tried searching but couldn't find it. |
This one I believe |
Sorry that's the overall 'kernel' fixup for native notebooks. This one is specifically remember remote kernel ids: |
I would like to point out that I'm using vscode with a jupyter notebook server I started myself (I just provide the extension with the URL including a token), and I still lose all my work whenever the SSH extension forces an editor reload. I'm using the Python interactive window. |
Yes the interactive window does not reuse kernels. It would be weird if it did. Perhaps we can detect the editor reload case but not sure. |
I'm sad to hear this. 😢 As someone who used Hydrogen before, I've seen firsthand the benefits of working with plain python files (that have cells delimited by |
Did Hydrogen leave the kernel around even after closing a python file? I think we'd have to do some other way of closing/creating kernels then. Some sort of kernel management story outside of what we do today. |
When connected to an outside notebook server, kernels would remain open until you shut them down manually (or stopped the notebook server itself). |
How did it know which kernel to use for a file? Did it associate one per python file? |
I used hydrogen in a kernel-per-file mode. When you first open a file, it starts out with no associated kernel. Then you can run a command to open up a kernel switcher that lets you select what Jupyter server you want and whether you want to connect to an existing kernel or spawn a new one. I believe hydrogen also had a global setting for having a single active Python kernel per editor window. With this setting enabled, the Python kernel would be reused automatically, but you wouldn't be able to get a second one without opening a new editor window. (The "one kernel" restriction in this mode is actually per programming language, so you could still have a python kernel for python files and then a Julia kernel in addition to that) |
For completeness (apologies for deviating from the original issue), I'd like to update and say this seems to only work if the kernel was started outside VSCode (e.g., by opening the notebook in the browser once and then attaching to that kernel manually). Even if the jupyter server is started outside of VSCode, but the kernel is started by VSCode when opening a file, VSCode kills the kernel when the tab is closed.
This sounds like an incredibly useful feature. The main reason I'm trying to use notebooks instead of the interactive window is because I need persistence, and I figured notebooks would be easier to make persistent than interactive windows. However, as far as I can tell, the hacky fix for both notebooks and interactive windows is to start the python kernel (not just the server) outside of VSCode and manually attach to that kernel. For notebooks, this setting will be remembered across sessions. For interactive windows, you'll need to re-attach to that kernel every time the tab or window is closed, but VSCode won't kill the kernel, at least on my version (1.50.0-insider, python extension 2020.9.114305). Not sure if there's an easier way. |
I'm dogfooding today and I find the lack of kernel management disturbing. I close a window and all the kernel data is lost? I hit close by accident and now I have to recreate my state? I really want a way to recreate my state on next startup. If this requires leaving the kernel running until I close it, that seems okay. Alternatively if the kernel could just be rehydrated, that would be cool too. (Kernel rehydration sounds interesting because you could send it places). |
Does it make sense to offer two options to users:
Essentially, I'm asking for jupyter-like behaviour, except that in option 2, the user decides when to start and shut down the server, no matter where it's running (local/remote). The user will be responsible for resource management. We're anyway used to doing that with Jupyter, this wouldn't be any different. And a panel that shows running kernels etc. would help greatly in making this whole thing transparent. |
In every other context, vscode seems to go to great lengths to maintain state across reloads / reconnects. So it's very surprising that vscode would nuke its jupyter server / kernels every time the window is reloaded or (if running as a ssh remote) the remote server is disconnected / reconnected. This strikes me as a pretty major misfeature. For example, if a terminal is open (locally or remote) and you reload the window, the state is maintained. If you disconnect from a remote session and then reconnect, the same terminal window is waiting for you with zero loss of state. This state preservation is one of the best features of the remote tools, and was clearly a design priority. So it's especially weird that the jupyter notebooks are the opposite, and (by design) lose their state so easily. Conceptually, a notebook session should be no different than a terminal session, and should have keep-alive behavior that matches. I would think it really should be considered a bug for a vscode-started jupyter server and its notebook sessions to end in circumstances that wouldn't end a terminal session. The problem is of course that there's a way to explicitly terminate a terminal session when the user is done with it, but not so for notebooks. A dialog asking whether vscode should terminate the session when closing a notebook's tab (and maybe when closing the whole window?) would probably be sufficient. It could also help to vscode explicitly pop up an alert when reconnecting to an existing session (with a "do you want to restart the session" as an option). Again, following the same keep-alive rules that the terminal does for its embedded sessions would be a really good start. It's good that some of these issues can be worked around by running an external jupyter server. (Of course, there are some bugs with that #5862...) But really there's no reason that servers started by vscode (which are much easier to work with, and play better with the debugger etc.) should not play by the same rules. Trashing user state like this is really a dealbreaker for doing substantial work with notebooks, especially on remote servers. |
Also want to say I agree. ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied: 'C:\\Users\\danie\\AppData\\Local\\Programs\\Python\\Python310\\Lib\\site-packages\\pywin32_system32\\pythoncom310.dll'
Consider using the `--user` option or check the permissions. So reinstalling packages with a |
Hi everyone, today you can manage some of the existing kernels (shut them down) using the following extension You'll need to open the |
+1 Leaving long computations running in a persistent kernel would be very nice. This is the main reason I use JupyterLab instead of vscode right now. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
We already have Jupyter servers on the remote clusters and can run kernels via vscode. The problem is as @cossio mentioned, vscode seems to quit the kernels if I quit the application. With Jupyter Lab, you can quit the browser and then later reconnect back to the same kernel (all computation retained), even from a different machine. My understanding is that's not currently possible on vscode because of this issue? |
Thanks for the detailed response. I'm wondering whether your answer is missing a step. How can one start a new jupyter session from vscode? From my understanding, it's required to start the session from jupyter notebook/lab and only then can you select it in vscode, correct? Or am I just missing some options to create a new session here? Edit: For anyone new to vscode and wondering the same thing: the very top option should create a new kernel. (I had another bug that prevented it from working, hence the confusion) |
Mine doesn't even show the list of kernels when I try to connect through the "http://localhost:{PORT}/?token={TOKEN}" existing jupyter instance. I would very much like the feature of jupyter notebook and jupyter lab of exiting the file and still having the kernel do it's job (training a model / data processing / et cetera). I am left to modify the code via vscode and run it via jupyter notebook which is silly |
Here is how I deal with this problem.
This way even if you quit |
Thanks @syo093c! To make it more concrete: Tutorial
That's it. As tmux always keeps the sesion alive, Jupyter doesn't care about your client shutting down or disconnecting. Note that theoretically more clients could connect to the same session. If you want to shut down the server eventually just reattach to the tmux session with |
Persistent Jupyter Sessions between VS Code Reloads/re-connectsFor those looking at persistent jupyter connections, such as @do-me @syo093c @MovsisyanM I'm sorry for pinging each of you, however the upvotes on issues help us prioritise issues. |
Feature: Notebook Editor, Interactive Window, Python Editor cells
I'd like to request manual kernel management, following the principles of: no kernel will ever be started without the user's explicit intent, and no kernel will ever be shut down without the user's intent.
Description
I just switched to using vscode about a month ago, and I find myself missing a large number of kernel management features that I'm used to from Atom+Hydrogen.
Here are some undesirable behaviors that I've observed:
All of these behaviors are driving me crazy. I just want a simple mode of operation where no kernel will be started without my consent, and no kernel will ever be shut down without my consent. I understand how the current behavior may be useful as a default, but there's not even an option for an alternative. For example in Atom+Hydrogen, using automatic kernel detection will trigger automatic kernel management just like vscode, but the moment you manually specify a Jupyter server URL it will switch to manual management.
Why is all of this a big issue for my workflow? Well, I work on machine learning, which seems to be well in scope of "data science" tools. My ML workloads have two key characteristics: (a) training can take hours or days and is not robust to unanticipated restarts (b) a GPU must be allocated for all python processes. Automatic shutdowns can cause me to lose up to days of work if I didn't save the model recently. Automatic startup and shutdown is also an issue because it creates a messy interaction with GPU scheduling/allocation. With Atom+Hydrogen things are so much simpler because I can just start a kernel manually, give it a GPU allocation, and I never have to worry about the tools creating extraneous kernels or deleting all my work when I didn't intend for that to happen.
Microsoft Data Science for VS Code Engineering Team: @rchiodo, @IanMatthewHuff, @DavidKutu, @DonJayamanne, @greazer, @joyceerhl
The text was updated successfully, but these errors were encountered: