Jupyter Kernel 连接¶
Jupyter Kernel 连接类型支持远程内核连接。
默认连接 ID¶
默认的 Jupyter Kernel 连接 ID 是
jupyter_kernel_default
。
配置连接¶
- host
远程 Jupyter Kernel 的主机名/IP
- Extra (可选)
指定可在内核连接中使用的额外参数(以 json 字典形式)。所有参数都是可选的。
session_key
: 用于启动与远程内核连接的会话密钥 [默认值: ‘’]。shell_port
: SHELL 端口 [默认值: 60316]。iopub_port
: IOPUB 端口 [默认值: 60317]。stdin_port
: STDIN 端口 [默认值: 60318]。control_port
: CONTROL 端口 [默认值: 60319]。hb_port
: HEARTBEAT 端口 [默认值: 60320]。
如果您通过 URI 配置连接,请确保 URI 的所有组成部分都经过 URL 编码。
示例¶
- 将远程内核连接设置为环境变量 (URI)
export AIRFLOW_CONN_JUPYTER_KERNEL_DEFAULT='{"host": "remote_host", "extra": {"session_key": "notebooks"}}'
- 创建 URI 连接的代码片段:
from airflow.models.connection import Connection conn = Connection( conn_id="jupyter_kernel_default", conn_type="jupyter_kernel", host="remote_host", extra={ # Specify extra parameters here "session_key": "notebooks", }, ) # Generate Environment Variable Name env_key = f"AIRFLOW_CONN_{conn.conn_id.upper()}" print(f"{env_key}='{conn.get_uri()}'")