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

Allow for custom kernel_spec_manager class #1404

Merged
merged 3 commits into from Oct 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/customize.md
Expand Up @@ -639,3 +639,21 @@ By using the [layout customization system](https://jupyterlab.readthedocs.io/en/
}
}
```

## Custom kernel_spec_manager class

By default, Voilà uses `jupyter_client`'s KernelSpecManager. To change this class, add the following to your config like so:

```py
import CustomKernelSpecManager

c.VoilaConfiguration.kernel_spec_manager_class = CustomKernelSpecManager
```

## Kernel startup_timeout

By default, Voilà's grace period for kernel startup time is 60 seconds. It can be adjusted as such, in seconds

```sh
voila --VoilaExecutor.startup_timeout=60
```
6 changes: 4 additions & 2 deletions voila/app.py
Expand Up @@ -35,7 +35,6 @@
import jinja2
import tornado.ioloop
import tornado.web
from jupyter_client.kernelspec import KernelSpecManager
from jupyter_core.paths import jupyter_config_path, jupyter_path
from jupyter_server.base.handlers import FileFindHandler, path_regex
from jupyter_server.config_manager import recursive_update
Expand Down Expand Up @@ -169,6 +168,7 @@ class Voila(Application):
"template": "VoilaConfiguration.template",
"theme": "VoilaConfiguration.theme",
"classic_tree": "VoilaConfiguration.classic_tree",
"kernel_spec_manager_class": "VoilaConfiguration.kernel_spec_manager_class",
}
classes = [VoilaConfiguration, VoilaExecutor, VoilaExporter]
connection_dir_root = Unicode(
Expand Down Expand Up @@ -544,7 +544,9 @@ def init_settings(self) -> Dict:
# default server_url to base_url
self.server_url = self.server_url or self.base_url

self.kernel_spec_manager = KernelSpecManager(parent=self)
self.kernel_spec_manager = self.voila_configuration.kernel_spec_manager_class(
parent=self
)

# we create a config manager that load both the serverconfig and nbconfig (classical notebook)
read_config_path = [
Expand Down
8 changes: 8 additions & 0 deletions voila/configuration.py
Expand Up @@ -158,6 +158,14 @@ def _valid_file_blacklist(self, proposal):
""",
)

kernel_spec_manager_class = Type(
config=True,
default_value="jupyter_client.kernelspec.KernelSpecManager",
klass="jupyter_client.kernelspec.KernelSpecManager",
help="""The kernel spec manager class. Allows for setting a custom kernel spec manager for finding and running kernels
""",
)

http_header_envs = List(
Unicode(),
[],
Expand Down
14 changes: 13 additions & 1 deletion voila/execute.py
Expand Up @@ -10,7 +10,7 @@
from nbclient.client import NotebookClient
from nbclient.exceptions import CellExecutionError
from nbconvert.preprocessors.clearoutput import ClearOutputPreprocessor
from traitlets import Bool, Unicode
from traitlets import Bool, Unicode, Integer


def strip_code_cell_warnings(cell):
Expand Down Expand Up @@ -50,6 +50,18 @@ class VoilaExecutor(NotebookClient):
help=("Whether to send tracebacks to clients on exceptions."),
)

startup_timeout: int = Integer(
60,
config=True,
help=(
"""
The time to wait (in seconds) for the kernel to start.
If kernel startup takes longer, a RuntimeError is
raised.
"""
),
)

def execute(self, nb, resources, km=None):
try:
result = super().execute()
Expand Down