From 1d5edf5de4a142088900dd8a3b7a52d3f0adbbc4 Mon Sep 17 00:00:00 2001 From: kangwoo Date: Sat, 27 Feb 2021 23:37:15 +0900 Subject: [PATCH] Fix problem that unable to get notebook filename on JupyterLab 3.0 --- kubeflow/fairing/notebook/notebook_util.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kubeflow/fairing/notebook/notebook_util.py b/kubeflow/fairing/notebook/notebook_util.py index eb9b2d3c..84d8141f 100644 --- a/kubeflow/fairing/notebook/notebook_util.py +++ b/kubeflow/fairing/notebook/notebook_util.py @@ -5,13 +5,19 @@ from notebook.notebookapp import list_running_servers import requests from requests.compat import urljoin +import importlib def get_notebook_name(): #pylint:disable=inconsistent-return-statements """Return the full path of the jupyter notebook. """ kernel_id = re.search('kernel-(.*).json', ipykernel.connect.get_connection_file()).group(1) - servers = list_running_servers() + jupyter_server_spec = importlib.util.find_spec("jupyter_server") + if jupyter_server_spec is not None: + from jupyter_server import serverapp + servers = serverapp.list_running_servers() + else: + servers = list_running_servers() for ss in servers: response = requests.get(urljoin(ss['url'], 'api/sessions'), params={'token': ss.get('token', '')})