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.

Explore using the interactive window as a console for notebook kernels

See original GitHub issue

From discussion with @greazer @rchiodo @claudiaregio @rebornix

Existing feature requests:

Proposed experience:

  • Command contributed to notebook/cell/title to open interactive window connected to same kernel
  • Command contributed to interactive/cell/title to paste code back into notebook
  • Kernel picker to be hidden
  • Sys info cell to indicate the notebook association
  • Context keys to hide interactive window specific functionality
  • Title should say ‘Scratchpad’
  • Should the interactive window immediately receive focus when created?

Bare-bones prototype: recording (7)

Open questions

Engineering notes:

  • Summary: Jupyter extension needs to refactor our VSCodeNotebookController wrapper, IKernel, and the cell execution codepath to allow
    • an IKernel that is currently mapped to a jupyter-notebook controller which has been selected for a given jupyter-notebook NotebookDocument
    • to be reused for an interactive controller that is selected for a given interactive NotebookDocument
  • Current state/background
    • Currently vscode.NotebookControllers are per-notebookType, so to get our kernels to show up for interactive windows, each of our kernels is registered twice with VS Code–once for the jupyter-notebook notebookType and once for the interactive notebookType
    • Our code currently assumes a 1-1 relationship between a VS Code NotebookController and our internal IKernel objects, i.e. controller is passed into IKernel constructor and then passed all the way down through the constructors of KernelExecution, CellExecutionQueue, CellExecution etc. in order to create the notebook cell execution task
    • Controllers can only create execution tasks for the NotebookDocument that they are currently associated with in VS Code
    • Our code currently also starts a new kernel for each new NotebookDocument in kernelProvider.getOrCreate
    • Interactive window needs to be passed a controller ID at creation to pick up the right controller (alternative is notebook.selectKernel or similar after the window is created, but we’ve discussed this and decided not to do it). NotebookDocument is returned from interactive.open, so given the jupyter-notebook controller currently selected for a Jupyter notebook, we need to find the matching interactive controller that we told VS Code about, and make sure that the underlying kernel is reused
    • Note, this also means that if we want arbitrary notebooks to be able to start an interactive session, then all those extensions must ensure that they return the same instance for jupyter-notebook and interactive notebookTypes (not guaranteed to work OOB)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:39
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
Rchatrucommented, Oct 7, 2021

I also join the petition. I recently switched from JupyterLab to VSCode, and this is an especially useful feature that makes it easier the daily work. It is quite common that at a certain moment we want to do some test with the variables, etc. in the notebook, and it is a bit clumsy to have to create new cells and then delete them again, especially when it is something that can be done in seconds from the interactive shell.

I think that all of us who work often with Jupyter Notebooks, would be very grateful if you could add this function.

8reactions
ishipachevcommented, Sep 22, 2021

I would be glad to see this implemented. My workflow around this feature would be like this:

  • write some code in a notebook
  • get some intermediate results and variables
  • experiment with some variables or functions in console without creating additional code cell and cleaning it after
  • put some outcomes of this experiments into notebook

Right now I can do it only in Interactive mode (with blocks starting with # %%), but this approach lacks of visual outputs I can have in notebooks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Jupyter code cells in the Python Interactive window
To use the window as a console, open it with the Jupyter: Create Interactive Window command from the Command Palette. You can then...
Read more >
Linking VS Code interactive window to running Jupyter ...
Linking VS Code interactive window to running Jupyter notebook ... JupyterLab the is accomplished with the New Console for Notebook command.
Read more >
Connecting to your notebook kernel using Jupyter console
Jupyter notebooks are a great way to explore data using Python (and other languages as well). Having a visual representation of your code...
Read more >
IPython Console — Spyder 5 documentation
To connect to a local kernel that is already running (e.g. one started by Jupyter notebook),. Run %connect_info in the notebook or console...
Read more >
Code Consoles — JupyterLab 3.6.0b0 documentation
Code consoles also display rich output, just like notebook cells. ... Use the up and down arrows to browse the history of previously-run...
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