Auto Select Kernel without Starting the Launcher So Users Don't Have To

Hello!

This question has been asked in two other places that I know of, but neither has received a response (see here and here).

How can I default select a kernel so that when JupyterLab starts up (via JupyterHub), the Launcher does not start and users don’t have to select a Kernel, and a JupyterLab Notebook is started automatically with the default kernel I’ve preconfigured?

There are five different XXX.default_kernel_name traitlets in the jupyter-server docs:

  1. MappingKernelManager
  2. MultiKernelManager
  3. AsyncMultiKernelManager
  4. AsyncMappingKernelManager
  5. GatewayMappingKernelManager

Their descriptions (all the same) of the functionality are appropriate for what I’m looking for, but since they all already default to python3, I believe there’s something else that needs to be configured.

Do I need to subclass jupyter_client.kernelspec.KernelSpecManager and implement my own logic?

After digging through source code, my best guess is to override MappingKernelManager.kernel_manager_class and implement my own _async_start_kernel (see here) but this seems like overkill.

Greatly appreciate the help!

1 Like

Bumping this. Judging from the other unanswered questions on this topic, seems like there’s interest.

Thank you.

What exactly do you mean by this? You want to open a “pre-configured” notebook when users spawn a single user server? If so you can do it with c.Spawner.default_url = /lab/tree/path/to/notebook.ipynb. But for this work, the notebook.ipynb must exist beforehand.

Appreciate the response mahendrapaipuri and apologies for the confusion. Hopefully my explanation below doesn’t create more ambiguity.

Re: launching a default notebook, I know that we can use c.Spawner.default_url = /lab/tree/path/to/notebook.ipynb to send users to a default notebook (for example, in the case of an onboarding notebook or similar), but I believe (please correct me if I’m wrong) that users will still have to select a kernel.

What we’re interested in is preconfiguring the environment so that jupyterlab always knows to default to the kernel we’ve preselected, unless they have explicitly started the launcher and selected a different kernel (like terminal).

In SonakshiGrover words:

Let’s suppose my notebook displays - ‘No Kernel’ on the top right, and I still try to execute cells which of course will give me no output since there is no kernel tied to my notebook. Now if I am a new user it will take me a few tries to realize that I need to manually select the kernel first and then execute the cells. To avoid this can I somehow attach a kernel to the notebook if a user tries to run any of its cells?

Alright. I see what you mean. Thanks for the explanation.

I think you will have to develop a frontend extension to achieve what you are trying to do rather than tweaking backend server settings. It is JupyterLab’s frontend that will show the Kernel Selector Dialog before starting the kernel.

So, the frontend will check if the kernelspec of current notebook file exists in the list of available kernelspecs. If not found, I think it will show the Kernel Selector Dialog for the user to select. So if I understood you well, you would like to override that behaviour and want your JupyterLab frontend to “pre-select” default kernel when kernelspec of current notebook file is not found in available kernelspecs. If so, I think it needs to be done with frontend extension. But take this with a grain of salt tho! Maybe there is aanother way to do it.

I guess you will have better luck posting this in JupyterLab or Notebook categories.

2 Likes

Thank you, @mahendrapaipuri! Appreciate the time you put into the response and for the helpful insight.

Will also post this in the JupyterLab / Notebook categories to see if anyone knows of another way to do it, but creating a frontend extension shouldn’t be too difficult.

1 Like