Skip to content

Commit 3fceb57

Browse files
committed
Use ensure_async to shut down kernel
1 parent 4b44d1f commit 3fceb57

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

share/jupyter/voila/templates/base/static/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ require([window.voila_js_url || 'static/voila'], function(voila) {
5252
// it seems if we attach this to early, it will not be called
5353
const matches = document.cookie.match('\\b_xsrf=([^;]*)\\b');
5454
const xsrfToken = (matches && matches[1]) || '';
55-
const configData = JSON.parse(document.getElementById('jupyter-config-data').textContent);
55+
const configData = JSON.parse(document.getElementById('jupyter-config-data').textContent);
5656
const baseUrl = configData.baseUrl;
5757
window.addEventListener('beforeunload', function (e) {
5858
const data = new FormData();

tests/app/shutdown_kernel_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import re
2+
3+
4+
async def test_shutdown_handler(http_server_client, base_url):
5+
response = await http_server_client.fetch(base_url)
6+
html_text = response.body.decode('utf-8')
7+
pattern = r"""kernelId": ["']([0-9a-zA-Z-]+)["']"""
8+
groups = re.findall(pattern, html_text)
9+
kernel_id = groups[0]
10+
shutdown_url = f'{base_url}voila/api/shutdown/{kernel_id}'
11+
shutdown_response = await http_server_client.fetch(shutdown_url, method='POST', body=b'')
12+
assert shutdown_response.code == 204

voila/shutdown_kernel_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import tornado
22
from jupyter_server.base.handlers import APIHandler
3+
from nbclient.util import ensure_async
34

45

56
class VoilaShutdownKernelHandler(APIHandler):
@@ -8,6 +9,6 @@ class VoilaShutdownKernelHandler(APIHandler):
89

910
@tornado.web.authenticated
1011
async def post(self, kernel_id):
11-
await self.kernel_manager.shutdown_kernel(kernel_id)
12+
await ensure_async(self.kernel_manager.shutdown_kernel(kernel_id))
1213
self.set_status(204)
1314
self.finish()

0 commit comments

Comments
 (0)