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

Add "Restart and run all" command #9242

Closed
greazer opened this issue Mar 5, 2022 Discussed in #9217 · 20 comments · Fixed by #13316 or #13342
Closed

Add "Restart and run all" command #9242

greazer opened this issue Mar 5, 2022 Discussed in #9217 · 20 comments · Fixed by #13316 or #13342
Assignees
Labels
feature-request Request for new features or functionality notebook-commands verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@greazer
Copy link
Member

greazer commented Mar 5, 2022

Discussed in #9217

Originally posted by benlindsay March 3, 2022
In the Jupyter toolbar, there's a Run All button

image

which looks a lot like the Restart and Run All button in Jupyter Lab

image

My initial expectation was that those buttons would be analogous, but in VSCode, it does not restart the kernel or clear outputs. Having that button fail to clear outputs is harmful because state from the previous run can be reused. For example, say you have a notebook with 2 cells:

print(foo)

and

foo = 42

If you run just the second cell, then click "Run All", your notebook will not fail even though it should. I can't think of any reason someone should want to rerun a notebook without also restarting the kernel. As for the clearing outputs bit, there is a case to be made for not clearing outputs, because it can be nice to see what was previously there. However, 2 points in favor of clearing outputs are 1) it would match behavior expectations from Jupyter Lab, and 2) when outputs are cleared prior to rerunning, it's much easier to tell where a failure occurred when scrolling through the notebook. Harder to tell when old outputs remain.

I hacked together a solution by adding a multicommand keybinding to keybindings.json, but that really shouldn't be necessary for a critical functionality. My keybinding looks like this:

{
  "key": "alt+r",
  "command": "extension.multiCommand.execute",
  "args": {
    "sequence": [
      "notebook.clearAllCellsOutputs",
      "jupyter.notebookeditor.restartkernel",
      "notebook.execute"
    ]
  },
  "when": "notebookEditable && activeEditor == 'workbench.editor.notebook'"
}

Thanks for all of y'all's work on this project!

@greazer
Copy link
Member Author

greazer commented Mar 9, 2022

After discussion and some analysis of other notebook implementations, it's not clear that just replacing "run all" with "restart and run all" is prudent. Instead, it seemed to be safer to simply add a way to accomplish this behavior in addition to the existing run-all via something like adding a new command in in the jupyter-extension that could be bound to a keystroke.

@greazer greazer changed the title Replace "Run all" button with "Restart and run all" button Add "Restart and run all" command Mar 9, 2022
@Hvass-Labs
Copy link

I have just started using VSCode and I like it a lot, but I agree that this is a problem. I come from using Jupyter Notebooks in an ordinary Google Chrome browser for Python development, so it is quite odd to only have the few buttons available in VSCode.

My workflow when doing R&D is often that I will change some parameters in a Notebook cell, and then re-run everything from that cell and below, so all the experiments are re-run with the new parameters, but there's no need to re-load data-files etc in the cells above.

But sometimes I like to restart the kernel and re-run the entire Notebook, just to make sure that I don't have old variables or function definitions lingering somewhere in the background.

Perhaps an idea is to make the Jupyter run-buttons customizable, so the user can decide which buttons to show in the menu-bar at the top of the Notebook editor?

Thanks!

@greazer greazer added feature-request Request for new features or functionality and removed enhancement labels May 4, 2022
@AwePhD
Copy link

AwePhD commented May 23, 2022

I support the idea to add a "Restart Kernel and Run all" command or/and button. Also, I think it would be confusing to use the current "Run all" button to perform this behavior.
Why not a customizable "Run all" button's behavior from settings, it is a good idea IMHO.

@DonJayamanne
Copy link
Contributor

There haven't been any up votes on this issue hence closing this for now

@TeamDman
Copy link

TeamDman commented Dec 4, 2022

I'm also interested just forgot to upvote D:

@jerpint
Copy link

jerpint commented Dec 7, 2022

I would also like to see a "restart and run all" button, it is a big part of my workflow

@DonJayamanne
Copy link
Contributor

Please do upvote the above issue, thats how we gauge interest in feature requests

@DonJayamanne DonJayamanne reopened this Dec 7, 2022
@jerpint
Copy link

jerpint commented Dec 7, 2022

@DonJayamanne by upvote, do you mean giving a 👍 to the original post?

@samruddhikhandale
Copy link
Member

I'd like to 👍 for this feature request because I usually get confused if the error/warnings are from a current/previous run. I do end up selecting Clear Outputs of All cells but would appreciate if it was done automatically (or with a single command).

@gubsey
Copy link

gubsey commented Mar 14, 2023

I can't believe this still isn't a feature

@Taytay
Copy link

Taytay commented Mar 29, 2023

As soon as this PR (microsoft/vscode#177722) lands in the mainline of VSCode, you can just add this to keybinding.json.

    {   // Restart and run all cells in Jupyter notebook
        "key": "alt+shift+r",
        "command": "runCommands",
        "args": {
            "commands": [
                "notebook.clearAllCellsOutputs",
                "jupyter.notebookeditor.restartkernel",
                "notebook.execute"
            ]
        },
        "when": "notebookEditorFocused"
    },

@Yoyokrazy
Copy link
Contributor

Just wanted to update people that this command is now released within VS code insiders via the daily pre-release of the jupyter extension. It will also be available at the next monthly stable release. The command is available via the command palette.

The command name is: Jupyter: Restart Kernel and Run All Cells
The command id is: jupyter.restartkernelandrunallcells

@erentar
Copy link

erentar commented Apr 16, 2023

Replacing the "Run All" button is not necessary. It is possible to add another button "Restart and Run All"

@Yoyokrazy
Copy link
Contributor

To clarify, the current toolbar button for Run All has not been replaced or altered. There is an additional command for Restart and Run All that has been added, and it currently does not have a button (only accessible via the command palette for now).

@rzhao271 rzhao271 added verified Verification succeeded verification-needed Verification of issue is requested labels Apr 26, 2023
@Hvass-Labs
Copy link

Thanks for adding this feature - but I really need the menu-button! :-)

It would also be practical if I could configure what exactly it does: I would like it to do a "Clear All" as well, but others may not like that.

Then I would probably remove the "Run All" button from my menu-bar as I don't need it anymore.

Thanks!

@nikitakuklev
Copy link

FYI restart action name changed to "jupyter.restartkernel"

@atticusmatticus
Copy link

@nikitakuklev it took me some time to find your comment and figure out why my restart keybinding wasn't working anymore. Is there a place where all the possible commands are listed that I'm not aware of? Seems like an extremely simple and useful thing to have in the Readme...

@Yoyokrazy
Copy link
Contributor

@atticusmatticus If you use the command palette (ctrl/cmd + shft + p), you can type "keyboard" and then open your keyboard shortcuts in either the UI or a JSON file. On the UI mode you can see where the command is contributed from as well, for example the Restart and Run All command is listed under the Jupyter Source.

@nikitakuklev
Copy link

To get the actual command name, I looked at the package.json file. Not sure if extensions must declare all commands there, but seems to work for a few common ones.

@Yoyokrazy
Copy link
Contributor

@nikitakuklev & @atticusmatticus
To get the command id, you can also do the following:

  • click on the gear, taking you to keyboard shortcuts
    image
  • Either refer to the search that auto populates into the shortcut search bar, or right click and copy the command id directly to your clipboard
    image

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality notebook-commands verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet