Add "Restart and run all" command
See original GitHub issueDiscussed in https://github.com/microsoft/vscode-jupyter/discussions/9217
<div type='discussions-op-text'>Originally posted by benlindsay March 3, 2022 In the Jupyter toolbar, there’s a Run All button
which looks a lot like the Restart and Run All button in Jupyter Lab
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!</div>
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:8 (3 by maintainers)
Top GitHub Comments
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.
@DonJayamanne by upvote, do you mean giving a 👍 to the original post?