Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align external kernel connections with jupyter-server #352

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion jupyverse_api/jupyverse_api/kernels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from fastapi import APIRouter, Depends, Request
from jupyverse_api import Router, Config
from pydantic import Field

from ..app import App
from ..auth import Auth, User
Expand Down Expand Up @@ -239,5 +240,19 @@ async def kernel_channels(

class KernelsConfig(Config):
default_kernel: str = "python3"
connection_path: Optional[str] = None
allow_external_kernels: bool = Field(
description=(
"Whether or not to allow external kernels, whose connection files are placed in "
"external_connection_dir."
),
default=False,
)
external_connection_dir: Optional[str] = Field(
description=(
"The directory to look at for external kernel connection files, if "
"allow_external_kernels is True. Defaults to Jupyter runtime_dir/external_kernels. "
"Make sure that this directory is not filled with left-over connection files."
),
default=None,
)
require_yjs: bool = False
11 changes: 8 additions & 3 deletions plugins/kernels/fps_kernels/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from jupyverse_api.yjs import Yjs
from jupyverse_api.app import App

from .kernel_driver.paths import jupyter_runtime_dir
from .routes import _Kernels


Expand All @@ -38,13 +39,17 @@ async def start(
kernels = _Kernels(app, self.kernels_config, auth, frontend_config, yjs)
ctx.add_resource(kernels, types=Kernels)

if self.kernels_config.connection_path is not None:
path = Path(self.kernels_config.connection_path)
if self.kernels_config.allow_external_kernels:
external_connection_dir = self.kernels_config.external_connection_dir
if external_connection_dir is None:
path = Path(jupyter_runtime_dir()) / "external_kernels"
else:
path = Path(external_connection_dir)
task = asyncio.create_task(kernels.watch_connection_files(path))

yield

if self.kernels_config.connection_path is not None:
if self.kernels_config.allow_external_kernels:
task.cancel()
for kernel in kernels.kernels.values():
await kernel["server"].stop()
Loading