Skip to content

Commit

Permalink
Merge pull request #597 from davidbrochart/nbclient
Browse files Browse the repository at this point in the history
Use async_start_new_kernel_client from nbclient
  • Loading branch information
SylvainCorlay committed Jun 15, 2020
2 parents 68e5e66 + a611b07 commit 20dd249
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 28 deletions.
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
21 changes: 2 additions & 19 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 Down

0 comments on commit 20dd249

Please sign in to comment.