# Restrict users creating multiple notebooks

**URL:** <https://discourse.jupyter.org/t/restrict-users-creating-multiple-notebooks/30289>\
**Category:** JupyterHub\
**Tags:** jupyterhub, notebook\
**Created:** [November 21, 2024, 6:58am UTC](https://discourse.jupyter.org/t/restrict-users-creating-multiple-notebooks/30289 "2024-11-21T06:58:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharun](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/tharun/32/16009_2.png) [@tharun](https://discourse.jupyter.org/u/tharun)\
**Post date:** [November 21, 2024, 6:58am UTC](https://discourse.jupyter.org/t/restrict-users-creating-multiple-notebooks/30289/1 "2024-11-21T06:58:04Z")

</div>

Is there a way to restrict users from creating/launching multiple notebooks? Many users have more than 10 notebooks which run in the background spawning multiple threads thereby exhausting the available memory.

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [November 22, 2024, 11:35am UTC](https://discourse.jupyter.org/t/restrict-users-creating-multiple-notebooks/30289/2 "2024-11-22T11:35:42Z")

</div>

You could use a custom SessionManager class that checks how many sessions are running in `create_session`. Something like:

```python
from tornado.web import HTTPError
from jupyter_server.services.sessions.sessionmanager import SessionManager

class LimitedSessionManager(SessionManager):
    session_limit = 2 # limit number of concurrent sessions
    async def create_session(self, *args, **kwargs):
        existing_sessions = await self.list_sessions()
        if len(existing_sessions) >= self.session_limit: 
            raise HTTPError(400, "Too many open sessions. Shutdown a notebook before opening a new one")
        return await super().create_session(*args, **kwargs)

c.ServerApp.session_manager_class.LimitedSessionManager

```

---

<div class="post-metadata">

**Author:** ![tharun](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/tharun/32/16009_2.png) [@tharun](https://discourse.jupyter.org/u/tharun)\
**Post date:** [November 23, 2024, 2:15am UTC](https://discourse.jupyter.org/t/restrict-users-creating-multiple-notebooks/30289/3 "2024-11-23T02:15:44Z")

</div>

Thank you, will update the config and let you know
