jtpio / ipylab

Control JupyterLab from Python Notebooks with Jupyter Widgets 🧪 ☢️ 🐍

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

change kernel

artttt opened this issue · comments

I was looking for the functionality to change the running kernel from code and came across this.
https://discourse.jupyter.org/t/is-there-magic-to-restart-kernel-change-kernel/10763/2

It was suggested that a github issue could be made (and as far as i can see it never happened) for some additional features "adding an argument that allows to skip the confirmation for kernelmenu:restart and pre-specify kernel for notebook:change-kernel"

Im most interested in being able to pre-specify the kernel for notebook:change-kernel.

I had a poke around the source to see if i could work out what to do but didn't make any progress unfortunately.

Thanks @artttt.

This would indeed be useful. iirc passing extra parameters should work already?

def execute(self, command_id, args=None):
args = args or {}
self.send({"func": "execute", "payload": {"id": command_id, "args": args}})

We need to check whether these two commands in JupyterLab accept such parameters.

I did a little looking at kernel changing.
looks like there are 2 commands that do the same thing notebook:change-kernel and kernelmenu:change.

They open the selectKernel dialog and as far as i can tell dont take an argument to do what we need.

Looking at the tests in jupyterlab it looks like ultimately the command that needs to be run is
await session.changeKernel({ name: differentkernelname });

my hunch is that there are 2 choices to add this functionality:

  1. a change to jupyterlab so that at least 1 of the 2 commands above has the option of taking an argument for a kernel name and skipping the selectKernel dialog if this argument is given.
  2. add code in ipylab to call changeKernel on the current session. app.sessions.current_session.change_kernel('name') or similar.