Код: Выделить всё
ipython profile create my_kernel --ipython-dir="./ipython_dir"Код: Выделить всё
ipython kernel -f="./confs/c1.json" --matplotlib --ipython-dir="./ipython_dir" --profile="my_kernel"
Код: Выделить всё
{
"shell_port": 33135,
"iopub_port": 45121,
"stdin_port": 33991,
"control_port": 37215,
"hb_port": 60399,
"ip": "127.0.0.1",
"key": "4ec201d6-fa1cefbd31693c09aa044b2a",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
Код: Выделить всё
ipython==8.22.2
jupyter_client==8.6.1
- Какой наиболее удобный способ взаимодействия с ядром IPython извне (скажем, client.py файл)? В настоящее время для связи я использую библиотеку jupyter_client.
Код: Выделить всё
import json
from jupyter_client.asynchronous.client import AsyncKernelClient
from jupyter_client.client import KernelClient
json_file = open("confs/c1.json", "r")
data = json.load(json_file)
shell_port = data["shell_port"]
iopub_port = data["iopub_port"]
stdin_port = data["stdin_port"]
control_port = data["control_port"]
hb_port = data["hb_port"]
kc = KernelClient(
ip="127.0.0.1",
transport="tcp",
shell_port=shell_port,
iopub_port=iopub_port,
stdin_port=stdin_port,
control_port=control_port,
hb_port=hb_port
)
code = """import os
current_dir = os.getcwd()
print("Current working directory:", current_dir)"""
msg_id = kc.execute(code)
- Мне нужно установить асинхронный канал связи с ядром IPython, чтобы обеспечить потоковую передачу вывода в реальном времени. Я считаю, что из jupyter_client.asynchronous.client импорт AsyncKernelClient является подходящим вариантом. Можете ли вы предоставить фрагмент кода, демонстрирующий этот подход?
- Последний: как закрепить ядро ipython для каждого пользователя и установить соединение до тех пор, пока пользователь убивает ядро или тайм-аут. (Я хочу использовать канал django)
Подробнее здесь: https://stackoverflow.com/questions/781 ... m-frontend