本文整理汇总了Python中notebook.notebookapp.list_running_servers方法的典型用法代码示例。如果您正苦于以下问题:Python notebookapp.list_running_servers方法的具体用法?Python notebookapp.list_running_servers怎么用?Python notebookapp.list_running_servers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类notebook.notebookapp
的用法示例。
在下文中一共展示了notebookapp.list_running_servers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: launch
# 需要导入模块: from notebook import notebookapp [as 别名]
# 或者: from notebook.notebookapp import list_running_servers [as 别名]
def launch(self, outputFilename, templateFilename=DefaultTemplate, port='auto'):
'''
Save and then launch this notebook
Parameters
----------
outputFilename : str
filename to save this notebook to
templateFilename : str, optional
filename to build this notebook from (see save_to)
'''
self.save_to(outputFilename, templateFilename)
outputFilename = _os.path.abspath(outputFilename) # for path manips below
from notebook import notebookapp
servers = list(notebookapp.list_running_servers())
for serverinfo in servers:
rel = _os.path.relpath(outputFilename, serverinfo['notebook_dir'])
if ".." not in rel: # notebook servers don't allow moving up directories
if port == 'auto' or int(serverinfo['port']) == port:
url = _os.path.join(serverinfo['url'], 'notebooks', rel)
_browser.open(url); break
else:
print("No running notebook server found that is rooted above %s" %
outputFilename)
示例2: test_zip
# 需要导入模块: from notebook import notebookapp [as 别名]
# 或者: from notebook.notebookapp import list_running_servers [as 别名]
def test_zip():
run_and_log("jupyter serverextension enable --py nbzip")
run_and_log("jupyter nbextension enable --py nbzip")
source_directory = 'testenv'
create_test_files(source_directory)
os.system("jupyter-notebook --port={} --no-browser &".format(PORT))
if (not wait_for_notebook_to_start()):
assert False, "Notebook server failed to start"
server = next(list_running_servers())
token = server['token']
try:
for fmt in ('zip', 'tar.gz'):
for path in ('Home', 'dir1/', 'dir1/dir2', 'dir1/dir3', 'dir4'):
check_zipped_file_contents(source_directory, path, token, fmt)
finally:
logging.info("Shutting down notebook server...")
os.system("jupyter notebook stop {}".format(PORT))
示例3: notebook_file_name
# 需要导入模块: from notebook import notebookapp [as 别名]
# 或者: from notebook.notebookapp import list_running_servers [as 别名]
def notebook_file_name(ikernel):
"""Return the full path of the jupyter notebook."""
# the following code won't work when the notebook is being executed
# through running `jupyter nbconvert --execute` this env var enables to
# overcome it
file_name = environ.get('JUPYTER_NOTEBOOK_FILE_NAME')
if file_name is not None:
return file_name
# Check that we're running under notebook
if not (ikernel and ikernel.config['IPKernelApp']):
return
kernel_id = re.search('kernel-(.*).json',
ipykernel.connect.get_connection_file()).group(1)
servers = list_running_servers()
for srv in servers:
query = {'token': srv.get('token', '')}
url = urljoin(srv['url'], 'api/sessions') + '?' + urlencode(query)
for session in json.load(urlopen(url)):
if session['kernel']['id'] == kernel_id:
relative_path = session['notebook']['path']
return path.join(srv['notebook_dir'], relative_path)
示例4: get_notebook_name
# 需要导入模块: from notebook import notebookapp [as 别名]
# 或者: from notebook.notebookapp import list_running_servers [as 别名]
def get_notebook_name() -> str:
"""Return the full path of the jupyter notebook.
References
----------
https://github.com/jupyter/notebook/issues/1000#issuecomment-359875246
"""
kernel_id = re.search( # type: ignore
'kernel-(.*).json', ipykernel.connect.get_connection_file()
).group(1)
servers = list_running_servers()
for server in servers:
response = requests.get(
urljoin(server['url'], 'api/sessions'), params={'token': server.get('token', '')}
)
for session in json.loads(response.text):
if session['kernel']['id'] == kernel_id:
relative_path = session['notebook']['path']
return pjoin(server['notebook_dir'], relative_path)
raise Exception('Noteboook not found.')