# Jupyter shutdown of idle kernels

**URL:** <https://discourse.openondemand.org/t/jupyter-shutdown-of-idle-kernels/1902>\
**Category:** Get Help\
**Created:** [February 8, 2022, 12:16pm UTC](https://discourse.openondemand.org/t/jupyter-shutdown-of-idle-kernels/1902 "2022-02-08T12:16:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![groucho64738](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/groucho64738/32/721_2.png) [@groucho64738](https://discourse.openondemand.org/u/groucho64738)\
**Post date:** [February 8, 2022, 12:16pm UTC](https://discourse.openondemand.org/t/jupyter-shutdown-of-idle-kernels/1902/1 "2022-02-08T12:16:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![groucho64738](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/groucho64738/32/721_2.png) [@groucho64738](https://discourse.openondemand.org/u/groucho64738)\
**Post date:** [February 8, 2022, 12:38pm UTC](https://discourse.openondemand.org/t/jupyter-shutdown-of-idle-kernels/1902/2 "2022-02-08T12:38:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![groucho64738](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/groucho64738/32/721_2.png) [@groucho64738](https://discourse.openondemand.org/u/groucho64738)\
**Post date:** [February 8, 2022, 1:06pm UTC](https://discourse.openondemand.org/t/jupyter-shutdown-of-idle-kernels/1902/3 "2022-02-08T13:06:18Z")

</div>

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

c.MappingKernelManager.cull\_connected = True

---

<div class="post-metadata">

**Author:** ![travert](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/travert/32/3074_2.png) [@travert](https://discourse.openondemand.org/u/travert)\
**Post date:** [February 8, 2022, 4:23pm UTC](https://discourse.openondemand.org/t/jupyter-shutdown-of-idle-kernels/1902/4 "2022-02-08T16:23:25Z")

</div>

Glad you figured it out!

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

---

<div class="post-metadata">

**Author:** ![azric](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/azric/32/63_2.png) [@azric](https://discourse.openondemand.org/u/azric)\
**Post date:** [February 8, 2022, 4:54pm UTC](https://discourse.openondemand.org/t/jupyter-shutdown-of-idle-kernels/1902/5 "2022-02-08T16:54:34Z")

</div>

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

```auto
# 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

```

---

<div class="post-metadata">

**Author:** ![groucho64738](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/groucho64738/32/721_2.png) [@groucho64738](https://discourse.openondemand.org/u/groucho64738)\
**Post date:** [February 10, 2022, 2:58pm UTC](https://discourse.openondemand.org/t/jupyter-shutdown-of-idle-kernels/1902/6 "2022-02-10T14:58:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/bae70bd0ed39a3ae769c2108155f4cb3e9da8385.png) [@system](https://discourse.openondemand.org/u/system)\
**Post date:** [August 9, 2022, 2:59pm UTC](https://discourse.openondemand.org/t/jupyter-shutdown-of-idle-kernels/1902/7 "2022-08-09T14:59:02Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
