Skip to content

Commit

Permalink
Inject session identifier into environment variable.
Browse files Browse the repository at this point in the history
There are many use case where users want to know the current notebook
name/path. This help by adding a session identifier (to not really say
this is the current notebook name), and by default make it the full path
to the notebook document that created the session.

This will of course not work if the notebook get renamed, but we can
tackle this later.

See also jupyter/jupyter_client#656,
jupyter#6180. It will need to be ported
to jupyter_server as well.
  • Loading branch information
Carreau committed Jan 26, 2022
1 parent 52581f8 commit 788bc3d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions notebook/services/sessions/sessionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from tornado import gen, web

from traitlets.config.configurable import LoggingConfigurable
from ipython_genutils.py3compat import unicode_type
from traitlets import Instance

from notebook.utils import maybe_future
Expand Down Expand Up @@ -86,7 +85,7 @@ def session_exists(self, path):

def new_session_id(self):
"Create a uuid for a new session"
return unicode_type(uuid.uuid4())
return str(uuid.uuid4())

@gen.coroutine
def create_session(self, path=None, name=None, type=None, kernel_name=None, kernel_id=None):
Expand All @@ -107,8 +106,13 @@ def start_kernel_for_session(self, session_id, path, name, type, kernel_name):
"""Start a new kernel for a given session."""
# allow contents manager to specify kernels cwd
kernel_path = self.contents_manager.get_kernel_path(path=path)

kernel_id = yield maybe_future(
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
self.kernel_manager.start_kernel(
path=kernel_path,
kernel_name=kernel_name,
env={"JPY_SESSION_NAME": path},
)
)
# py2-compat
raise gen.Return(kernel_id)
Expand Down

0 comments on commit 788bc3d

Please sign in to comment.