當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。