ipylab icon indicating copy to clipboard operation
ipylab copied to clipboard

change kernel

Open artttt opened this issue 3 years ago • 2 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.

artttt avatar Apr 06 '22 05:04 artttt

Thanks @artttt.

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

https://github.com/jtpio/ipylab/blob/bf2713243a53bded508f62a833a8ebeef4abb038/ipylab/commands.py#L58-L60

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

jtpio avatar Apr 09 '22 16:04 jtpio

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.

artttt avatar Apr 10 '22 12:04 artttt