Jupyter shutdown of idle kernels

Hi. This may be a little off-topic, but has anyone implemented any type of idle shutdown culling in Jupyter when launched through OnDemand? It seems like most of the stuff I’m seeing online is related to JupyterHub, but just figured I’d ask if someone has done it just with JupyterLab.

I’ve modified our before.sh.erb script for the Jupyter app to add these lines when the jupyter configuration is generated:

c.MappingKernelManager.cull_idle_timeout = 600
c.MappingKernelManager.cull_interval = 120

…but it doesn’t seem to do anything.

Thanks.

In my output log, it looks like the setting is validated:
[I 2022-02-08 07:26:45.799 ServerApp] Culling kernels with idle durations > 600 seconds at 120 second intervals …

Definitely not doing anything though. I have a kernel that’s still idle

Ok. I think I’ve got it working now. Might have been one more option:

c.MappingKernelManager.cull_connected = True

Glad you figured it out!

Sorry we couldn’t help in time but if you hit anymore snags please let us know.

It took some exploring, but found a couple of wrinkles. This SEEMS to work at our site. This is based loosely non some bits I found online (no memory of where). Adding c.NotebookApp.shutdown_no_activity_timeout
was the piece that seemed to make it all work. This is an addition to the config file created by Jupyter’s template/before.sh.erb

# shutdown the server after no activity for 20 minutes
c.NotebookApp.shutdown_no_activity_timeout = 20 * 60
# shutdown kernels after no activity for 10 minutes
c.MappingKernelManager.cull_idle_timeout = 10 * 60
# Check every minute
c.MappingKernelManager.cull_interval = 60
# cull connected (e.g. Browser tab open)
c.MappingKernelManager.cull_connected = True

I considered the notebookapp shutdown, but what concerned me about that is that if a user just sits there idle for awhile, that the entire jupyter session might get killed. I don’t know if that’s true or not (I didn’t test it), but it seems I was successful with just the last 3 settings.