发现哪个内核已经启动 [英] discovering which kernel has been started

查看:92
本文介绍了发现哪个内核已经启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:我正在Docker容器中生成Notebook服务器(版本5),并且拥有一个系统,用户可以在其中选择他们希望启动的多个Notebook内核之一(因此,Docker映像).

Environment : I am spawning Notebook Servers (version 5) in Docker Containers, and have a system where users may select one of several Notebook kernels (thus, docker images) they wish to start.

我需要在笔记本服务器页面上添加一个指示器,以指示已启动了哪个特定内核.

I have a need to add an indicator to the notebook server page to indicate which particular kernel has been started.

我已经有修改page.htmltree.html模板的模板,因此可以将我需要的内容添加到 html 没问题....我无法解决的问题是我如何从Docker容器获取一些数据到Notebook Server渲染代码.

I already have templates that modify the page.html and tree.html templates, so can add whatever I need into the html no problem.... what I'm failing to work out is how I get some piece of data from the Docker Container to the Notebook Server rendering code.

我推断这可能是通过向jupyter_notebook_config.py文件中添加一些内容而实现的-但找不到任何方法可以帮助您.

I'm deducing that it will probably be by adding something to the jupyter_notebook_config.py file - but can't find anything to help either way.

有人这样做吗?

推荐答案

感谢Jupyter开发人员...我有一个解决方案:

With thanks to the Jupyter development peoples... I have a solution:

jupyter_notebook_config.py中,您可以设置一个字典:

In jupyter_notebook_config.py you can set a dict:

c.NotebookApp.jinja_template_vars = {'Ian_1':'One','ian_2':'Two'}

读取模板中的数据

在您的Jinja模板文件中,可能有一个获取参数的块.在tree.html中,它看起来像这样:

Reading data in the templates

In your Jinja template file, there's probably a block for getting parameters. In tree.html it looks like this:

{% block params %}
{{super()}}
data-base-url="{{base_url | urlencode}}"
data-notebook-path="{{notebook_path | urlencode}}"
data-terminals-available="{{terminals_available}}"
data-server-root="{{server_root}}"
{% endblock %}

您需要做的所有事情都会添加到变量中(显然,它们是区分大小写的)....例如:

All you need to do it add in your variables (obviously, they are case-sensitive).... eg:

{% block params %}
{{super()}}
data-base-url="{{base_url | urlencode}}"
data-notebook-path="{{notebook_path | urlencode}}"
data-terminals-available="{{terminals_available}}"
data-server-root="{{server_root}}"
ian_1="{{ian_1}}"
ian_2="{{ian_2}}"
{% endblock %}

(请注意Ian_1的大小写不正确)

(note the incorrect case-match for Ian_1)

现在,如果您在笔记本中查看/tree页面的源代码,则会在body标记的属性中找到它们:

if you now look at the source code of the /tree page in your notebook, you'll find them as attributes to the body tag:

<body class=""
     data-jupyter-api-token="<token-string>"
     data-base-url="/"
     data-notebook-path=""
     data-terminals-available="True"
     data-server-root="/home/jovyan"
     ian_1=""
     ian_2="Two"
     dir="ltr">

(请注意,由于大小写不匹配,ian_1为空白.)

(and note that ian_1 is blank due to the case mis-match.)

您现在可以将变量用作Jinja中的任何其他变量(根据 http://jinja.pocoo.org /)

You can now use the variable as any other variable in Jinja (as per http://jinja.pocoo.org/)

这篇关于发现哪个内核已经启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆