Skip to content

Commit

Permalink
Multi-instance and multi-version of Jupyter Notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
abaelhe committed Sep 3, 2020
1 parent 07570c6 commit 978d883
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions notebook/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""The Jupyter HTML Notebook"""

import os

JUPYTER_NOTEBOOK_TAG = "JupyterNotebook"

# Packagers: modify this line if you store the notebook static files elsewhere
DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static")

Expand Down
3 changes: 2 additions & 1 deletion notebook/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from notebook.i18n import combine_translations
from notebook.utils import is_hidden, url_path_join, url_is_absolute, url_escape, urldecode_unix_socket_path
from notebook.services.security import csp_report_uri
from notebook import JUPYTER_NOTEBOOK_TAG

#-----------------------------------------------------------------------------
# Top-level handlers
Expand Down Expand Up @@ -849,7 +850,7 @@ class APIVersionHandler(APIHandler):

def get(self):
# not authenticated, so give as few info as possible
self.finish(json.dumps({"version":notebook.__version__}))
self.finish(json.dumps({"version": notebook.__version__, "module": JUPYTER_NOTEBOOK_TAG}))


class TrailingSlashHandler(web.RequestHandler):
Expand Down
6 changes: 4 additions & 2 deletions notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
from tornado.netutil import bind_unix_socket

from notebook import (
JUPYTER_NOTEBOOK_TAG,
DEFAULT_NOTEBOOK_PORT,
DEFAULT_STATIC_FILES_PATH,
DEFAULT_TEMPLATE_PATH_LIST,
Expand Down Expand Up @@ -2327,9 +2328,10 @@ def list_running_servers(runtime_dir=None):
# Actively check whether that process is really available via an HTTP request
# Also remove leftover files from IPython 2.x without a pid field
response = kernel_request(info, path=url_path_join(info.get('base_url') or '/','/api'))
if response.body == api_version_json_bytes:
try:
assert JUPYTER_NOTEBOOK_TAG == json.loads(response.body)["module"]
yield info
else:
except:
# If the process has died, try to delete its info file
try:
os.unlink(os.path.join(runtime_dir, file_name))
Expand Down

0 comments on commit 978d883

Please sign in to comment.