question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add "Restart and run all" command

See original GitHub issue

Discussed 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

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!</div>

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
greazercommented, 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.

3reactions
jerpintcommented, Dec 7, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jupyter/IPython Notebooks: Shortcut for "run all"?
Esc (unselect potential cells or edit modes). Ctrl A (select all cells). Shift Enter (run all selected).
Read more >
How to create a shortcut for 'restart and run all' in JupyterLab
How to create a shortcut for 'restart and run all' in JupyterLab. In the updated version of the Jupyter Lab, you might not...
Read more >
My favorite Jupyter Notebook shortcuts as a newbie
Restart kernel and run all cells: Shift + R; Toggle all cells output collapsed (collapse all cells' output): Ctrl + Shift + O;...
Read more >
Jupyter Notebook Shortcuts - Towards Data Science
You can also edit existing or add more shortcuts from the Help > Edit ... I added a shortcut Ctrl-R for the restart...
Read more >
Restart and Run all cells in Kernel or Jupyter notebook by ...
To restart kernel by executing cell we can use this. from IPython.display import HTML, Javascript, display def restart_kernel_and_run_all_cells(): ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found