Skip to content

Commit 788bc3d

Browse files
committed
Inject session identifier into environment variable.
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, #6180. It will need to be ported to jupyter_server as well.
1 parent 52581f8 commit 788bc3d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

notebook/services/sessions/sessionmanager.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from tornado import gen, web
1515

1616
from traitlets.config.configurable import LoggingConfigurable
17-
from ipython_genutils.py3compat import unicode_type
1817
from traitlets import Instance
1918

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

8786
def new_session_id(self):
8887
"Create a uuid for a new session"
89-
return unicode_type(uuid.uuid4())
88+
return str(uuid.uuid4())
9089

9190
@gen.coroutine
9291
def create_session(self, path=None, name=None, type=None, kernel_name=None, kernel_id=None):
@@ -107,8 +106,13 @@ def start_kernel_for_session(self, session_id, path, name, type, kernel_name):
107106
"""Start a new kernel for a given session."""
108107
# allow contents manager to specify kernels cwd
109108
kernel_path = self.contents_manager.get_kernel_path(path=path)
109+
110110
kernel_id = yield maybe_future(
111-
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
111+
self.kernel_manager.start_kernel(
112+
path=kernel_path,
113+
kernel_name=kernel_name,
114+
env={"JPY_SESSION_NAME": path},
115+
)
112116
)
113117
# py2-compat
114118
raise gen.Return(kernel_id)

0 commit comments

Comments
 (0)