Skip to content

Commit

Permalink
allow the session manager to persist on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsailer committed Nov 17, 2021
1 parent a1b013e commit 3812cf5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions jupyter_server/services/sessions/sessionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@

from traitlets.config.configurable import LoggingConfigurable
from traitlets import Instance
from traitlets import Unicode

from jupyter_server.utils import ensure_async
from jupyter_server.traittypes import InstanceFromClasses


class SessionManager(LoggingConfigurable):

database_path = Unicode(
default_value=":memory:",
help="Filesystem path to SQLite Database file. Does not write to file by default."
).tag(config=True)

kernel_manager = Instance("jupyter_server.services.kernels.kernelmanager.MappingKernelManager")
contents_manager = InstanceFromClasses(
[
Expand All @@ -39,7 +45,7 @@ def cursor(self):
if self._cursor is None:
self._cursor = self.connection.cursor()
self._cursor.execute(
"""CREATE TABLE session
"""CREATE TABLE IF NOT EXISTS session
(session_id, path, name, type, kernel_id)"""
)
return self._cursor
Expand All @@ -48,7 +54,8 @@ def cursor(self):
def connection(self):
"""Start a database connection"""
if self._connection is None:
self._connection = sqlite3.connect(":memory:")
# Set isolation level to None to autocommit all changes to the database.
self._connection = sqlite3.connect(self.database_path, isolation_level=None)
self._connection.row_factory = sqlite3.Row
return self._connection

Expand Down

0 comments on commit 3812cf5

Please sign in to comment.