Restrict users creating multiple notebooks

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.

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

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
1 Like

Thank you, will update the config and let you know