Skip to content

Commit

Permalink
Allow for custom kernel_spec_manager class (#1404)
Browse files Browse the repository at this point in the history
* Allow for custom kernel spec manager class

* Added startup_timeout config

---------

Co-authored-by: castrom <[email protected]>
  • Loading branch information
ClaytonAstrom and castrom authored Oct 25, 2023
1 parent 42a00f6 commit 9a8147a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
18 changes: 18 additions & 0 deletions docs/customize.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 9a8147a

Please sign in to comment.