Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent session storage #614

Merged
merged 6 commits into from
Dec 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Zsailer marked this conversation as resolved.
Show resolved Hide resolved
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