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

Use async_start_new_kernel_client from nbclient #597

Merged
merged 7 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion share/jupyter/voila/templates/lab/index.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var voila_process = function(cell_index, cell_count) {
Therefore it is important to have the cell loop in the template.
The issue for Jinja is: https://github.com/pallets/jinja/issues/1044
#}
{%- for cell in cell_generator(nb, kernel_id) -%}
{%- for cell in cell_generator(nb) -%}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we don't need the kernel id in the jupyter-config-data?

I recall there was a comment by @maartenbreddels about this, but don't remember what.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jupyter-config-data gets the kernel_id from kernel_start().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deja vu feeling here :), I think it was a different PR. We do need the kernel_id, otherwise, we break the API, and we lose flexibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{% set cellloop = loop %}
{%- block any_cell scoped -%}
<script>
Expand Down
2 changes: 1 addition & 1 deletion tests/app/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def voila_config():

@pytest.fixture
def voila_args_extra():
return []
return ['--VoilaExecutor.timeout=240']


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/app/execute_cpp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def cpp_file_url(base_url):

@pytest.fixture
def voila_args_extra():
return ['--VoilaConfiguration.extension_language_mapping={".xcpp": "C++11"}']
return ['--VoilaConfiguration.extension_language_mapping={".xcpp": "C++11"}', '--VoilaExecutor.timeout=240']


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/app/many_iopub_messages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@pytest.fixture
def voila_args_extra():
return ['--ExecutePreprocessor.timeout=180']
return ['--VoilaExecutor.timeout=180']


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/app/no_strip_sources_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@pytest.fixture
def voila_args_extra():
return ['--VoilaConfiguration.strip_sources=False']
return ['--VoilaConfiguration.strip_sources=False', '--VoilaExecutor.timeout=240']


async def test_no_strip_sources(http_server_client, base_url):
Expand Down
2 changes: 1 addition & 1 deletion tests/app/template_arg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@pytest.fixture
def voila_args_extra():
return ['--template=test_template']
return ['--template=test_template', '--VoilaExecutor.timeout=240']


async def test_template(http_server_client, base_url):
Expand Down
2 changes: 1 addition & 1 deletion tests/app/template_cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def voila_args_extra():
path_test_template = os.path.abspath(os.path.join(BASE_DIR, '../test_template/share/jupyter/voila/templates/test_template/'))
path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/default'))
return ['--template=None', '--VoilaTest.template_paths=[%r, %r]' % (path_test_template, path_default)]
return ['--template=None', '--VoilaTest.template_paths=[%r, %r]' % (path_test_template, path_default), '--VoilaExecutor.timeout=240']


async def test_template_test(http_server_client, base_url):
Expand Down
2 changes: 1 addition & 1 deletion tests/app/template_config_file_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def voila_args_extra():
path_test_template = os.path.abspath(os.path.join(BASE_DIR, '../test_template/share/jupyter/voila/templates/test_template/nbconvert_templates'))
path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/default/nbconvert_templates'))
return ['--template=test_template', '--Voila.nbconvert_template_paths=[%r, %r]' % (path_test_template, path_default)]
return ['--template=test_template', '--Voila.nbconvert_template_paths=[%r, %r]' % (path_test_template, path_default), '--VoilaExecutor.timeout=240']


async def test_template_test(http_server_client, base_url):
Expand Down
2 changes: 1 addition & 1 deletion tests/app/template_custom_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@pytest.fixture
def voila_args_extra():
return ['--template=None']
return ['--template=None', '--VoilaExecutor.timeout=240']


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/app/tree_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def voila_args(notebook_directory, voila_args_extra):

@pytest.fixture
def voila_args_extra():
return ['--VoilaConfiguration.extension_language_mapping={".xcpp": "C++11"}']
return ['--VoilaConfiguration.extension_language_mapping={".xcpp": "C++11"}', '--VoilaExecutor.timeout=240']


async def test_tree(http_server_client, base_url):
Expand Down
23 changes: 3 additions & 20 deletions voila/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,8 @@ def redirect_to_file(self, path):

async def _jinja_kernel_start(self):
assert not self.kernel_started, "kernel was already started"
kernel_id = await self.kernel_manager.start_kernel(kernel_name=self.notebook.metadata.kernelspec.name, path=self.cwd)
km = self.kernel_manager.get_kernel(kernel_id)
# When Voila is launched as an app, its kernel manager's type is AsyncMappingKernelManager, and thus
# its kernel client's type is AsyncKernelClient.
# But this has to be explicitly configured when launched as a server extension, with e.g.:
# --ServerApp.kernel_manager_class=jupyter_server.services.kernels.kernelmanager.AsyncMappingKernelManager
# If it's not done, the kernel manager might not be async, which is not a big deal, but we want the kernel
# client to be async, so we explicitly configure it for this particular case:
km.client_class = 'jupyter_client.asynchronous.AsyncKernelClient'
self.executor = VoilaExecutor(self.notebook, km=km, config=self.traitlet_config)
self.executor.kc = km.client()
self.executor.kc.start_channels()
try:
await self.executor.kc.wait_for_ready(timeout=self.executor.startup_timeout)
except RuntimeError:
self.executor.kc.stop_channels()
self.executor.km.shutdown_kernel()
raise
self.executor.kc.allow_stdin = False
self.executor = VoilaExecutor(self.notebook, km=self.kernel_manager, config=self.traitlet_config)
kc, kernel_id = await self.executor.async_start_new_kernel_client(kernel_name=self.notebook.metadata.kernelspec.name, path=self.cwd)
self.kernel_started = True
return kernel_id

Expand All @@ -146,7 +129,7 @@ async def _jinja_notebook_execute(self, nb, kernel_id):
# see the updated variable (it seems to be local to our block)
nb.cells = result.cells

async def _jinja_cell_generator(self, nb, kernel_id):
async def _jinja_cell_generator(self, nb):
"""Generator that will execute a single notebook cell at a time"""
nb, resources = ClearOutputPreprocessor().preprocess(nb, {'metadata': {'path': self.cwd}})

Expand Down