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

Enable KernelSpecResourceHandler to be async #1236

Merged
merged 1 commit into from
Mar 13, 2023
Merged
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
12 changes: 7 additions & 5 deletions jupyter_server/kernelspecs/handlers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Kernelspecs API Handlers."""
from jupyter_core.utils import ensure_async
from tornado import web

from jupyter_server.auth import authorized
Expand All @@ -21,23 +22,24 @@ def initialize(self):

@web.authenticated
@authorized
def get(self, kernel_name, path, include_body=True):
async def get(self, kernel_name, path, include_body=True):
"""Get a kernelspec resource."""
ksm = self.kernel_spec_manager
if path.lower().endswith(".png"):
self.set_header("Cache-Control", f"max-age={60*60*24*30}")
try:
self.root = ksm.get_kernel_spec(kernel_name).resource_dir
kspec = await ensure_async(ksm.get_kernel_spec(kernel_name))
self.root = kspec.resource_dir
except KeyError as e:
raise web.HTTPError(404, "Kernel spec %s not found" % kernel_name) from e
self.log.debug("Serving kernel resource from: %s", self.root)
return web.StaticFileHandler.get(self, path, include_body=include_body)
return await web.StaticFileHandler.get(self, path, include_body=include_body)

@web.authenticated
@authorized
def head(self, kernel_name, path):
async def head(self, kernel_name, path):
"""Get the head infor for a kernel resource."""
return self.get(kernel_name, path, include_body=False)
return await ensure_async(self.get(kernel_name, path, include_body=False))


default_handlers = [
Expand Down