当前位置: 首页>>代码示例>>Python>>正文


Python notebookapp.list_running_servers方法代码示例

本文整理汇总了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) 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:27,代码来源:notebook.py


示例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)) 
开发者ID:data-8,项目名称:nbzip,代码行数:24,代码来源:test_nbzip.py


示例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) 
开发者ID:nuclio,项目名称:nuclio-jupyter,代码行数:26,代码来源:utils.py


示例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.') 
开发者ID:jwkvam,项目名称:bowtie,代码行数:23,代码来源:_magic.py



注:本文中的notebook.notebookapp.list_running_servers方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。