Culling idle kernels in Jupyter Server inside docker

Hi everyone,

I am trying to achieve the culling of idle kernels in JupyterLab. As per my investigation, there are two jupyter_server_config.py files that are present in the docker environment at the following locations:

  1. /etc/jupyter/jupyter_server_config.py
  2. /home/jovyan/.jupyter/jupyter_server_config.py

The content of these two files is completely different. In the first file, it is a configuration file with different parameters preceding c. and I can see the fields to set the time interval for c.MappingKernelManager.cull_idle_timeout and c.MappingKernelManager.cull_interval. Whereas the second file is a python script where these two lines are missing. When I see my docker logs I found that the file being used is the first file and not the second.

I pass the c.MappingKernelManager.cull_idle_timeout and c.MappingKernelManager.cull_interval parameters (originally absent) in the first file but it does not work for some reason and does not cull the idle servers.

Here are the logs:

Patching auth into notebook.base.handlers.IPythonHandler(notebook.base.handlers.AuthenticatedHandler) -> IPythonHandler(jupyterhub.singleuser.mixins.HubAuthenticatedHandler, notebook.base.handlers.AuthenticatedHandler)
[I 2022-04-27 18:55:10.492 SingleUserLabApp mixins:614] Starting jupyterhub single-user server version 2.2.0
[I 2022-04-27 18:55:10.492 SingleUserLabApp mixins:628] Extending jupyterlab.labhubapp.SingleUserLabApp from jupyterlab 3.2.5
[I 2022-04-27 18:55:10.492 SingleUserLabApp mixins:628] Extending jupyter_server.serverapp.ServerApp from jupyter_server 1.13.1
[D 2022-04-27 18:55:10.510 SingleUserLabApp application:174] Searching ['/home/jovyan', '/home/jovyan/.jupyter', '/home/jovyan/.local/etc/jupyter', '/opt/conda/etc/jupyter', '/usr/local/etc/jupyter', '/etc/jupyter'] for config files
[D 2022-04-27 18:55:10.511 SingleUserLabApp application:731] Looking for jupyter_config in /etc/jupyter
[D 2022-04-27 18:55:10.511 SingleUserLabApp application:731] Looking for jupyter_config in /usr/local/etc/jupyter
[D 2022-04-27 18:55:10.511 SingleUserLabApp application:731] Looking for jupyter_config in /opt/conda/etc/jupyter
[D 2022-04-27 18:55:10.511 SingleUserLabApp application:731] Looking for jupyter_config in /home/jovyan/.local/etc/jupyter
[D 2022-04-27 18:55:10.512 SingleUserLabApp application:731] Looking for jupyter_config in /home/jovyan/.jupyter
[D 2022-04-27 18:55:10.512 SingleUserLabApp application:731] Looking for jupyter_config in /home/jovyan
[D 2022-04-27 18:55:10.513 SingleUserLabApp application:731] Looking for jupyter_server_config in /etc/jupyter
[D 2022-04-27 18:55:10.514 SingleUserLabApp application:753] Loaded config file: /etc/jupyter/jupyter_server_config.py
[D 2022-04-27 18:55:10.514 SingleUserLabApp application:731] Looking for jupyter_server_config in /usr/local/etc/jupyter
[D 2022-04-27 18:55:10.514 SingleUserLabApp application:731] Looking for jupyter_server_config in /opt/conda/etc/jupyter
[D 2022-04-27 18:55:10.514 SingleUserLabApp application:731] Looking for jupyter_server_config in /home/jovyan/.local/etc/jupyter
[D 2022-04-27 18:55:10.514 SingleUserLabApp application:731] Looking for jupyter_server_config in /home/jovyan/.jupyter
[D 2022-04-27 18:55:10.515 SingleUserLabApp application:731] Looking for jupyter_server_config in /home/jovyan
```

I tested it locally on my computer (without docker) and it culls idle kernels after a specific time interval.